0
我碰到一個問題,即時通訊嘗試的PHP腳本。所以當我啓動它時,腳本完美地連接到MySQL和數據庫,但是當我嘗試從'代碼'數據庫中選擇數據時,它會給我一個這樣的錯誤:「無法獲取數據:」。它應該做的是說「無法獲取數據:(然後是錯誤)」,但它沒有。先謝謝了。 :)PHP select MySQL給出未知錯誤
PHP代碼:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
mysqli_select_db($dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
$sql = 'SELECT code FROM codes';
$retval = mysql_query($sql, $conn);
if(! $retval) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "Code:{$row['code']}";
}
echo "Fetched data successfully\n";
mysql_close($conn);
?>
要結合'mysql'&'mysqli'。僅在每個操作中使用'mysqi' –
您正在將mysqli與mysql混合 –
您檢查數據庫名稱。 –