我正在尝试从数据库中获取数据,但遇到了此错误。
致命错误:未捕获错误:调用E:\xamp\htdocs\PoliceApp\News\fetch中未定义的函数mysql_select_db()。php:10堆栈跟踪:E:\xamp\htdocs\PoliceApp\News\fetch中抛出#0{main}。第10行的php
我怎样才能纠正这一点?
<?php
$username="root";
$password="namungoona";
$hostname = "localhost";
//connection string with database
$dbhandle = mysqli_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "";
// connect with database
$selected = mysql_select_db("police",$dbhandle)
or die("Could not select examples");
//query fire
$result = mysql_query("select * from News;");
$json_response = array();
// fetch data in array format
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// Fetch data of Fname Column and store in array of row_array
$row_array['Headlines'] = $row['Headlines'];
$row_array['Details'] = $row['Details'];
$row_array['NewsPhoto'] = $row['NewsPhoto'];
//push the values in the array
array_push($json_response,$row_array);
}
//
echo json_encode($json_response);
?>
1条答案
按热度按时间vom3gejh1#
它应该是
mysqli_select_db($dbhandle, "police")
,其他mysql_*
函数也应该更改为mysqli_*
。