PDO statements not working on a live host

▼魔方 西西 提交于 2020-01-03 04:34:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!