此代码出现错误:
致命错误:在非对象上调用成员函数prepare()C:UsersfelVertrigoServwwwloginvalidation.php 第 42 行
Fatal error: Call to a member function prepare() on a non-object in C:UsersfelVertrigoServwwwloginvalidation.php on line 42
代码:
function repetirDados($email) {
if(!empty($_POST['email'])) {
$query = "SELECT email FROM users WHERE email = ?";
$stmt = $pdo->prepare($query); // error line: line 42
$email = mysql_real_escape_string($_POST['email']);
$stmt->bindValue(1, $email);
$ok = $stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($results == 0) {
return true;
} else {
echo '<h1>something</h1>';
return false;
}
}
}
可能的原因是什么?另一个问题,mysql_num_rows 等价于什么?抱歉,我是 pdo 的新手
What is the possible cause? Another question, What is the equivalent to mysql_num_rows? sorry, I am newbie with pdo
$pdo 未定义.您没有在函数内部声明它,也没有将其作为参数传入.
$pdo is undefined. You're not declaring it inside the function, and it isn't being passed in as an argument.
您需要将它传入(好),或者在全局命名空间中定义它,并通过将 global $pdo 放在顶部(不好)使其可用于您的函数.
You need to either pass it in (good), or define it in the global namespace and make it available to your function by placing global $pdo at the top (bad).
这篇关于pdo - 在非对象上调用成员函数 prepare()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
MySQLi准备好的语句&foreach 循环MySQLi prepared statement amp; foreach loop(MySQLi准备好的语句amp;foreach 循环)
mysqli_insert_id() 是从整个服务器还是从同一用户获Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是从整个服务器还是从同一用户获取记录?)
PHP MySQLi 无法识别登录信息PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 无法识别登录信息)
mysqli_select_db() 需要 2 个参数mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 个参数)
Php mysql pdo 查询:用查询结果填充变量Php mysql pdo query: fill up variable with query result(Php mysql pdo 查询:用查询结果填充变量)
MySQLI 28000/1045 用户“root"@“localhost"的访问MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用户“root@“localhost的访问被拒绝)