0
localhostを設定しましたが、関連するすべてのファイルが用意されています。私はSQLクエリを実行するPHPを実行し、NULL値を返します。しかし、それはすべきではない。私はブラウザを介してリンクのディレクトリにアクセスします。localhostからのヌルリターンPHPケーキ
誰かが帰りの方向に私を指し示すことができます、なぜそれはNULLを返すのですか?私は、SQLクエリを実行し、あなたが期待するものではありません
<?php
header('Content-Type: application/json');
define('DB_HOST', '127.0.0.1');
define('DB_USERNAME', 'myusername');
define('DB_PASSWORD', 'Ihavenopassword');
define('DB_NAME', 'mytablename');
$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
//$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if(!$mysqli){
die("Connection failed: " . $mysqli->error);
}
//query to get data from the table
$query = sprintf("SELECT playerid, score FROM score ORDER BY playerid");
//execute query
$result = $mysqli->query($query);
//loop through the returned data
$data = array();
foreach ($result as $row) {
$data[] = $row;
}
//free memory associated with result
$result->close();
//close connection
$mysqli->close();
//now print the data
print json_encode($data);
こんにちは。それでも0の結果を返します。この発生の可能性はありますか? – user8890638
解決済み、ありがとう!私は、($ row = mysqli_fetch_assoc($ result)){(mysqli_num_rows($ result)> 0){ //各行の出力データを while – user8890638