If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

there is neither a PDO->connect_error nor a PDOStatement->num_rows nor a PDOStatement->fetch_object() property/method in PDO (these are all MySQLi properties/methods, PDO uses CamelCase).

additionally, there is no need to use a loop for a single result set. and the catch() statement should be placed after all of the DB code.

btw. you don’t even need to test the number of results. if there is no (more) result available PDOStatement->fetchObject() returns false, and since you can only have one result at most ...

The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.

PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

(colouring by me)

The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.

Actually, with a little bit of sensible logic, the number of results in a SELECT statement do not need to be fetched separately. for most of the other cases, there is SQL’s COUNT() function.

The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.