2 回答
TA贡献1799条经验 获得超9个赞
您需要在任何地方正确使用连接变量名称。(在$conn您的情况下,它是,但您使用了$link)
<?php
/* Database credentials. Assuming you are running MySQL
server with default setting (user 'root' with password 'root') */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'root');
define('DB_NAME', 'startup');
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
/* check connection */
if (!$conn) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$param_username = "user1";
$stmt = mysqli_prepare($conn, "SELECT id, username, password FROM users WHERE `username` = ?");
mysqli_stmt_bind_param($stmt, "s", $param_username);
/* execute prepared statement */
mysqli_stmt_execute($stmt);
printf("%d Row inserted.\n", mysqli_num_rows($stmt));
/* close statement and connection */
mysqli_stmt_close($stmt);
/* close connection */
mysqli_close($conn);
?>
TA贡献1804条经验 获得超2个赞
你做错了什么,请更新并尝试
$sql = "SELECT id, username, password FROM users WHERE username = ?";
$stmt = mysqli_prepare($link, $sql);
$param_username = "user1";
mysqli_stmt_bind_param($stmt, "s", $param_username);
mysqli_stmt_execute($stmt);
- 2 回答
- 0 关注
- 151 浏览
添加回答
举报