php 未捕获的错误:调用未定义的函数 mysql_select_db()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40650747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught Error: Call to undefined function mysql_select_db()
提问by Lutaaya Huzaifah Idris
I'm trying to fetch data from the database using Xamp Server but am getting this error.
我正在尝试使用 Xamp Server 从数据库中获取数据,但出现此错误。
Fatal error: Uncaught Error: Call to undefined function mysql_select_db() in E:\xamp\htdocs\PoliceApp\News\fetch.php:10 Stack trace: #0 {main} thrown in E:\xamp\htdocs\PoliceApp\News\fetch.php on line 10
致命错误:未捕获错误:调用 E:\xamp\htdocs\PoliceApp\News\fetch.php:10 中未定义的函数 mysql_select_db() 堆栈跟踪:#0 {main} 抛出在 E:\xamp\htdocs\PoliceApp\News \fetch.php 第 10 行
Below is my phpscript , am still new in phpplease help me out on this. But i read all the other Posts here but it seems it's confusing to me,how can I make it right please.
下面是我的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);
?>
回答by bansi
As per your request i have modified code.
根据您的要求,我修改了代码。
<?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);
?>
Please note: you need to add error checking. Also note just typed in here (not tested), so bear with me if there are some errors.
请注意:您需要添加错误检查。还要注意这里只是输入(未测试),如果有一些错误,请多多包涵。
回答by RazerX
Just change mysql to myqsli in your php code because the XAMPP (I guess) is reading SQLi not SQL correctly
只需在您的 php 代码中将 mysql 更改为 myqsli,因为 XAMPP(我猜)正在正确读取 SQLi 而不是 SQL