未捕获的错误:调用未定义的函数mysql_select_db()

Lut*_*ris 4 php

我正在尝试使用Xamp Server从数据库中获取数据但是收到此错误.

致命错误:未捕获错误:在E:\ xamp\htdocs\PoliceApp\News\fetch.php中调用未定义函数mysql_select_db():10堆栈跟踪:#0 {main}抛出E:\ xamp\htdocs\PoliceApp\News第10行的\ fetch.php

下面是我的PHP脚本,我仍然是新的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);  
?>  
Run Code Online (Sandbox Code Playgroud)

ban*_*nsi 14

根据您的要求,我修改了代码.

<?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 = mysqli_select_db($dbhandle, "police")  
or die("Could not select examples");  
//query fire  
$result = mysqli_query($dbhandle,"select * from News;");  
$json_response = array();  
// fetch data in array format  
while ($row = mysqli_fetch_array($result, MYSQLI_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); 
mysqli_free_result($result);
?>
Run Code Online (Sandbox Code Playgroud)

请注意:您需要添加错误检查.另请注意只需键入此处(未测试),如果有错误请耐心等待.