獲取錯誤:mysqli_select_db()期望的是2個參數
警告:mysqli_select_db()期望的是2個參數,1 C中給出:\用戶\根\桌面\ Web服務器\ htdocs中\ test.php的上線9
警告:mysqli_query()預計至少2個參數,1 C中給出:\用戶\根\桌面\ Web服務器\ htdocs中\ test.php的上線路13
警告:mysqli_fetch_assoc()預計參數1爲mysqli_result,null在第39行的C:\ Users \ root \ Desktop \ WebServer \ htdocs \ test.php中給出。
我不能注意到這個問題,新的這種,任何人都可以看到問題?
任何幫助非常感謝!
<?php
//make connection
mysqli_connect('localhost', 'root', '');
//select db
mysqli_select_db('altislife-dev');
$sql="SELECT * FROM players";
$records=mysqli_query($sql);
?>
<html>
<head>
<title>Data</title>
</head>
<body>
<table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>uid</th>
<th>name</th>
<th>aliases</th>
<th>playerid</th>
<th>cash</th>
<th>bankacc</th>
<th>coplevel</th>
<tr>
<?php
while($players=mysqli_fetch_assoc($records)) {
echo "<tr>";
echo "<td>".$players['uid']."</td>";
echo "<td>".$players['name']."</td>";
echo "<td>".$players['aliases']."</td>";
echo "<td>".$players['playerid']."</td>";
echo "<td>".$players['cash']."</td>";
echo "<td>".$players['bankacc']."</td>";
echo "<td>".$players['coplevel']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
您使用的是'mysql_'語法。您需要將連接分配給一個變量'$ mysqli = mysqli_connect(...);',然後使用它作爲'select_db'和'query'函數中的第一個參數,例如'mysqli_select_db($ mysqli,「.. .. 。「);''''和'mysqli_query($ mysqli,$ sql)' – Qirel
或者,只需刪除'mysqli_select_db()',並在連接中指定DB:'$ mysqli = mysqli_connect('localhost','root',' ','altislife-dev');' – Qirel