gpt4 book ai didi

php - 从 mysql 转换为 PDO 用户名确认问题

转载 作者:太空宇宙 更新时间:2023-11-03 10:46:45 25 4
gpt4 key购买 nike

如何将此 mysql 转换为 PDO?我在尝试获取验证用户名是否已存在的代码时遇到问题。

//Check if user already exists

$u_check = mysql_query("SELECT username FROM users WHERE username='$un'");

//Count the amount of rows where username = $un

$check = mysql_num_rows($u_check);



if ($check == 0) {

最佳答案

您可能希望使用 prepared statement 来执行此操作

$u_check = $pdo->prepare("SELECT username FROM users WHERE username= :username");
$u_check->execute(array(':username' => $un));
if($u_check->rowCount()) {

关于php - 从 mysql 转换为 PDO 用户名确认问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30632030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com