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

问题描述 投票:5回答:2

我正在尝试使用Xamp Server从数据库中获取数据,但遇到此错误。

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

下面是我的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);  
?>  
php
2个回答
17
投票

根据您的要求,我已修改代码。


0
投票

只需将您的php代码中的mysql更改为myqsli,因为XAMPP(我想)正在正确读取SQLi,而不是SQL


0
投票

[Koneksi berhasil致命错误:未捕获错误:调用C:\ xampp \ htdocs \ pertanian \ index.php中未定义的函数mysql_select_db():13堆栈跟踪:#0 {main}引发C:\ xampp \ htdocs \ pertanian \ index.php在第13行

© www.soinside.com 2019 - 2024. All rights reserved.