title: SQL statements in javaScript AJAX request
body: <p>I've been programming only in JavaScript and now I'd like to work with some databases and learn SQL. I'm wondering if it is common and safe attitude, to send SQL statements in the AJAX requests, for example like this:</p>
  
  <pre><code>xhttp= new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 &amp;&amp; this.status == 200) {
       //something
    }
  };
  var sql = 'SELECT * FROM Customers'; //creating SQL statements in JS like this
  xhttp.open("GET", "getFromDatabase.php?q="+sql, true);
  xhttp.send();
  
  //PHP:
  $result = mysqli_query($con,$q);
  echo $result;
  </code></pre>
  
  <p>instead of keeping and generating all necessary SQL statements inside the php file indicated in AJAX open() like this:</p>
  
  <pre><code>xhttp= new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 &amp;&amp; this.status == 200) {
       //something
    }
  };
  xhttp.open("GET", "getFromDatabase.php?q=getCustomers", true);
  xhttp.send();
  
  //PHP:
  if ($q==="getCustomers") {
      $sql="SELECT * FROM Customers";  //here are ALL SQL statements
      $result = mysqli_query($con,$sql);
      echo $result;
  }
  </code></pre>
  
  <p>All the tutorials and samples on the Internet I've read up prefer the second attitube, but for me - who do not know PHP and don't want to learn at this time - the first (JS) attitude would be easier, just for learning and testing how to handle databases. Then I could create a simple php file just for returning JSON with some data and all other stuff do in JavaScript.</p>