How to query database using javascript?

后端 未结 8 1228
渐次进展
渐次进展 2020-12-09 20:07

Another question by a newbie. I have a php variable that queries the database for a value. It is stored in the variable $publish and its value will change (in the database)

8条回答
  •  孤街浪徒
    2020-12-09 20:37

    I'll try to leave the technical jargon aside and give a more generic response since I think you might be confused with client-side and server-side scripting.

    Think of javascript as a language that can only instruct your WEB BROWSER how to act. Javascript executes after the server has already finished processing your web page.

    PHP on the other hand runs on your web server and has the ability to communicate with your database. If you want to get information from your database using javascript, you'll need to have javascript ask PHP to query the database through an AJAX call to a PHP script.

    For example, you could have javascript call a script like: http://www.myserver.com/ajax_function.php?do=queryTheDatabase

    In summary: Javascript can't connect to the database but it can ask PHP to do so. I hope that helps.

提交回复
热议问题