我是这个mysqli + php世界的新手。目前,我是从TutorialsPoint
中学到的我的设置
Xampp版本:7.3.2 / PHP 7.3.2
好像在这里有点问题。
无法获取数据:您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在第2行的'$ tutorial_count'附近使用
<?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysqli_error($conn));
}
if( isset($tutorial_count )) {
$sql = 'SELECT tutorial_author, tutorial_count FROM tcount_tbl
WHERE tutorial_count = $tutorial_count';
} else {
$sql = 'SELECT tutorial_author, tutorial_count
FROM tcount_tbl WHERE tutorial_count IS $tutorial_count';
}
mysqli_select_db($conn, 'TUTORIALS');
$retval = mysqli_query($conn, $sql );
if(! $retval ) {
die('Could not get data: ' . mysqli_error($conn));
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "Author:{$row['tutorial_author']} <br> ".
"Count: {$row['tutorial_count']} <br> ".
"--------------------------------<br>";
}
echo "Fetched data successfully\n";
mysqli_close($conn);
?>
这是我的数据库;
任何帮助将不胜感激。谢谢。