Xamp Server를 사용하여 데이터베이스에서 데이터를 가져오려고 하는데 이 오류가 발생합니다.
치명적인 오류입니다: 잡히지 않은 오류입니다: 정의되지 않은 함수에 대한 호출
E:\xamp\htdocs\PoliceApp\News\fetch.php:10 스택의 mysql_select_db() trace: #0 {메인}이 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
$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);
?>
참고: 오류 검사를 추가해야 합니다. 또한 여기에 방금 입력한 내용(테스트되지 않음)이므로 오류가 있어도 양해해 주시기 바랍니다.