W3school中示例PHP / AJAX的问题

I have read a example of PHP/AJAX in https://www.w3schools.com/php/php_ajax_database.asp

$con = mysqli_connect('localhost','peter','abc123','my_db');
if (!$con) {
  die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");

为什么需要两次声明数据库。首先,在mysqli_connect中使用my_db,然后在mysqli_select_db中使用ajax_demon,复制所有代码后,我无法执行ajax的效果。

评论
gest
gest

There's no reason to connect to the server with the my_db database, never use it, then immediately switch to the ajax_demo database.

This is just W3Schools being of their usual low quality (as is the massive SQL injection security hole on the first line after mysqli_select_db)

点赞
评论