我从PHP文件中收到此错误:
The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
这是相关代码的副本:
<?php
$con = mysql_connect("localhost","username","password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database_name", $con);
$result = mysql_query("SELECT COUNT(*) FROM `tbltodolist` WHERE status = 'Pending'");
$row = mysql_fetch_array($result);
$total = $row[0];
echo $total;
mysql_close($con);
?>
有没有简单的方法可以将其切换为使用mysqli来避免错误?
答案 0 :(得分:1)
以这种方式使用mysqli以避免通知。因为新版本的php不推荐使用mysql。
<?php
$con = mysqli_connect("localhost","username","password","database_name");
if (!$con) {
die('Could not connect: ' . mysqli_error());
}
$result = mysqli_query($con,"SELECT COUNT(*) FROM `tbltodolist` WHERE status = 'Pending'");
$row = mysqli_fetch_array($result);
$total = $row[0];
echo $total;
mysqli_close($con);
?>
答案 1 :(得分:0)