我在MySQL的數(shù)據(jù)庫(kù)中有一個(gè)表(“模塊數(shù)據(jù)庫(kù)”),我需要通過(guò)編寫(xiě)php腳本在服務(wù)器上打印出該表(非常簡(jiǎn)單,兩行帶有名稱(chēng)的“ Fnamn”和“ Enamn”),使用MySQL。問(wèn)題是:它不起作用。文檔(.php)的html部分工作正常(h1出現(xiàn)在屏幕上),但我什么也沒(méi)得到??赡苁鞘裁磫?wèn)題呢 ?嘗試了幾種不同的方法,甚至通過(guò)從w3學(xué)校(https://www.w3schools.com/php/php_mysql_select.asp)復(fù)制/粘貼并更改了一些變量,但沒(méi)有進(jìn)行任何更改(結(jié)果為“ 0”) W3一個(gè),現(xiàn)在沒(méi)有新的)。<h1>Script modul</h1><?php$servername = "localhost";$username = "antony";$password = "thepassword";$dbname = "antony";// Create connection$conn = new mysqli($servername, $username, $password, $dbname);// Check connectionif ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);}$query = "SELECT * FROM moduledatabas";$result = mysqli_query($query);if (!$result) { $message = 'Invalid query: ' . mysqli_error() . "\n"; $message .= 'Whole query: ' . $query; die($message);}while ($row = mysqli_fetch_assoc($result)) { echo $row['Fnamn']; echo $row['Enamn'];}mysqli_free_result($result);
1 回答

慕標(biāo)5832272
TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
你有沒(méi)有過(guò)$conn
在你的mysqli_query()
,只是改變?nèi)缦旅娴拇a:
$query = "SELECT * FROM moduledatabas"; $result = mysqli_query($conn,$query);
有關(guān)更多信息,請(qǐng)參考mysqli_query
- 1 回答
- 0 關(guān)注
- 167 瀏覽
添加回答
舉報(bào)
0/150
提交
取消