PDO语句不适用于实时主机 [英] PDO statements not working on a live host
问题描述
PDO语句可在localhost上运行,但无法在实时主机上运行.这是一个在localhost上正常运行的示例,但rowCount()始终在活动主机上返回0.有人请帮助我.
PDO statements work on localhost but fail to work on a live host. here is an example that works fine on localhost but rowCount() always returns 0 on a live host. someone please help me.
$stmt = $pdo->prepare("SELECT * FROM customer WHERE email = :email AND password = :password");
$stmt->execute(array(
':email' => $uemail,
':password' => $pass
));
$count = $stmt->rowCount();
推荐答案
PDOStatement :: rowCount
PDOStatement :: rowCount()返回受DELETE,INSERT或UPDATE语句影响的行数.
PDOStatement::rowCount() returns the number of rows affected by a DELETE, INSERT, or UPDATE statement.
这对SELECT
不起作用,具有讽刺意味的是,但确实如此:)
That does not work for SELECT
, ironic but true :)
解决方法:
对于大多数数据库,PDOStatement :: rowCount()不会返回受SELECT语句影响的行数.而是使用PDO :: query()发出与所要SELECT语句相同的谓词的SELECT COUNT(*)语句,然后使用PDOStatement :: fetchColumn()检索将返回的行数.然后,您的应用程序可以执行正确的操作.
For most databases, PDOStatement::rowCount() does not return the number of rows affected by a SELECT statement. Instead, use PDO::query() to issue a SELECT COUNT(*) statement with the same predicates as your intended SELECT statement, then use PDOStatement::fetchColumn() to retrieve the number of rows that will be returned. Your application can then perform the correct action.
甚至不能在localhost上运行.您在本地主机上错误地解释了结果.
Should not even work on localhost. You're interpreting the result incorrectly on localhost.
Manual
这篇关于PDO语句不适用于实时主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!