我想显示在我的网页 从MySQL数据库中的信息,但是这个代码不工作,我得到了一个错误:如何在网页上显示来自mySQL数据库的信息?
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\student2.php on line 28.
我不知道什么是错的 程序,我不知道如何解决这个问题。
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("testdb");
if($con){
echo "Successfully connected to the database.";
}else{
die("Error.");
}
if($db){
echo "Sucessfully found the database.";
}else{
die("Error.Database not found.");
}
?>
$query=mysql_query("SELECT * FROM testdb");
while($row=mysql_fetch_array($query)){
$name=$row['name'];
$nomatrix=$row['nomatrix'];
}
?>
2017-10-18
girl7432
+0
仅供参考,[你不应该在新代码'mysql_ *'功能(http://stackoverflow.com /问题/ 12859942 /)。他们不再被维护[并被正式弃用](https://wiki.php.net/rfc/mysql_deprecation)。看到[红盒](http://php.net/manual/en/function.mysql-connect.php)?学习[*准备的语句*](https://en.wikipedia.org/wiki/Prepared_statement),并使用[PDO](http://php.net/pdo)或[MySQLi](http:// php.net/mysqli) - [这篇文章](http://php.net/manual/en/mysqlinfo.api.choosing.php)将帮助你决定哪一个最适合你。 –