1

Is it possible? I don't want to use PHP for querying, so can I use it only for the connection while using javascript code for the query?

It'd be great if someone can provide an example of it.

Zuberi
  • 35
  • 6

1 Answers1

1

You can't query MySQL through JS because by default JS is clientside meaning it has no direct access to the databse server. If that were possible then anyone could just edit your JS and query whatever they want from the DB.

You can potentially use AJAX to call a PHP function from inside your JS code but all database queries have to be done through PHP since that's where you create the connection.

If you wanted to build your own request in JS then you'd have to switch to a framework like AngularJS or Node.js where the back-end is written in JS rather than PHP, but these are more complex.

Grumbunks
  • 1,027
  • 1
  • 7
  • 21