gpt4 book ai didi

php - Uncaught Error : Call to undefined function mysql_select_db()

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:56:29 24 4
gpt4 key购买 nike

我正在尝试从数据库中获取数据,但出现此错误。

Fatal error: Uncaught Error: Call to undefined functionmysql_select_db() in E:\xamp\htdocs\PoliceApp\News\fetch.php:10 Stacktrace: #0 {main} thrown in E:\xamp\htdocs\PoliceApp\News\fetch.php online 10

我怎样才能做到这一点?

<?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);
?>

最佳答案

应该是 mysqli_select_db($dbhandle, "police") 其他 mysql_* 函数也应该改成它们的 mysqli_* .

<?php

$username = "root";
$password = "namungoona";
$hostname = "localhost";

// enable error reporting
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

// connection string with database
$dbhandle = mysqli_connect($hostname, $username, $password);

// connect with database
$selected = mysqli_select_db($dbhandle, "police");

// 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);

关于php - Uncaught Error : Call to undefined function mysql_select_db(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40650747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com