如何在使用Wamp时获得这些已弃用的错误,使我的查询或脚本正常工作我在使用Xampp时没有收到错误。我得到的错误或警告就在这张照片上
这是我的PHP脚本
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$result = mysql_query("SELECT gender as gender_occupation, COUNT(*) as total FROM hostel_blocks GROUP BY gender");
$rows = array();
while($r = mysql_fetch_array($result)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rows,$row);
}
print json_encode($rows, JSON_NUMERIC_CHECK);
mysql_close($con);
?>
当我更改了一些连接代码时,我得到了一个空白页面。
答案 0 :(得分:0)
PHP mysql在PHP 5.5中已弃用,并从PHP 7开始删除 你应该转移到mysqli。
使用mysqli的代码如下所示:
<?php
$con = mysqli_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db( $con, "db");
$result = mysqli_query($con, "SELECT gender as gender_occupation, COUNT(*) as total FROM hostel_blocks GROUP BY gender");
$rows = array();
while($r = mysqli_fetch_array($result)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rows,$row);
}
print json_encode($rows, JSON_NUMERIC_CHECK);
mysqli_close($con);
?>