问题
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();
回答1:
PDOStatement::rowCount
PDOStatement::rowCount() returns the number of rows affected by a DELETE, INSERT, or UPDATE statement.
That does not work for SELECT, ironic but true :)
Workaround:
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.
Should not even work on localhost. You're interpreting the result incorrectly on localhost.
Manual
来源:https://stackoverflow.com/questions/26750542/pdo-statements-not-working-on-a-live-host