問題描述
獲取錯誤:
警告:mysqli_select_db() 需要 2 個參數(shù),1 個在 C:Users ootDesktopWebServerhtdocs est.php 第 9 行
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:Users ootDesktopWebServerhtdocs est.php on line 9
警告:mysqli_query() 需要至少 2 個參數(shù),其中 1 個在 C:Users ootDesktopWebServerhtdocs est.php 第 13 行
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:Users ootDesktopWebServerhtdocs est.php on line 13
警告:mysqli_fetch_assoc() 期望參數(shù) 1 為 mysqli_result,空值在 C:Users ootDesktopWebServerhtdocs est.php 第 39 行
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:Users ootDesktopWebServerhtdocs est.php on line 39
我沒注意到這個問題,有點陌生,有人能看到問題嗎?
I can't notice the problem, kind of new to this, can anyone see the problem?
非常感謝任何幫助!
<?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>
推薦答案
做如下更正:
$conn = mysqli_connect('localhost', 'root', '');
首先必須將 select_db 中的連接變量作為第一個參數(shù)傳遞.如下.
the first thing that you have to pass connection variable in the select_db as first parameter. as below.
mysqli_select_db($conn,'altislife-dev');
您還必須將 mysqli_query() 中的連接變量作為第一個參數(shù)傳遞,如下所示.
also you have to pass connection variable in mysqli_query() as first parameter as given below.
$records=mysqli_query($conn,$sql);
這篇關(guān)于mysqli_select_db() 需要 2 個參數(shù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!