我试图在浏览器中显示从数据库中获取的一些数据,当我运行它时,它显示以下错误:
mysqli_error() 期望参数 1 为 mysqli,给定 null
我会很感激一些帮助。
代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
</head>
<body>
<table border='1px'>
<tr>
<td class='fila'>id</td>
<td class='fila'>Nombre</td>
<td class='fila'>Apellido</td>
</tr>
<?php
$host="localhost";
$usuario="php";
$password="prueba";
$basedatos="clientes";
$connection = mysqli_connect($host,$usuario,$password);
function showerror( ) {
die("Se ha producido el siguiente error: " . mysqli_error($connection));
}
// Seleccionar la base de datos
if (!(@ mysqli_select_db($basedatos, $connection)))
showerror( );
$SQL=" SELECT id_cliente,nombre,apellido FROM clientes.datos where
fecha_creacion between '2018-06-15' and '2018-06-01' ";
if (!($result1 = @ mysqli_query ( $SQL, $connection)))
showerror( );
while ($row1 = mysqli_fetch_row($result1)) {
print("<tr>");
print("<td class='fila'>".$row1[0]."</td>");
print("<td class='fila'>".$row1[1]."</td>");
print("<td class='fila'>".$row1[2]."</td>");
print("</tr>");
}
?>
</body>
</html>
这可能是因为您的连接字符串。尝试放置:
通过在连接字符串中包含 db,不再需要此代码段:
最后,您调试的代码如下:
有关更多信息,您可以查看mysql_query
希望对你有帮助,问候!