mysqli_select_db() 需要 2 个参数
获取错误:
警告:mysqli_select_db() 需要 2 个参数,1 个在 C:UsersootDesktopWebServerhtdocs est.php 第 9 行
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:UsersootDesktopWebServerhtdocs est.php on line 9
警告:mysqli_query() 需要至少 2 个参数,其中 1 个在 C:UsersootDesktopWebServerhtdocs est.php 第 13 行
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:UsersootDesktopWebServerhtdocs est.php on line 13
警告:mysqli_fetch_assoc() 期望参数 1 为 mysqli_result,空值在 C:UsersootDesktopWebServerhtdocs est.php 第 39 行
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:UsersootDesktopWebServerhtdocs 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 中的连接变量作为第一个参数传递.如下.
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() 中的连接变量作为第一个参数传递,如下所示.
also you have to pass connection variable in mysqli_query() as first parameter as given below.
$records=mysqli_query($conn,$sql);
相关文章