How-to articles, tricks, and solutions about PDO

Checking for an empty result (PHP, PDO, and MySQL)

In PHP, you can use the PDO (PHP Data Objects) extension to interact with a MySQL database.

Connect to SQL Server through PDO using SQL Server Driver

Here is an example of how to connect to a SQL Server database using PDO and the SQL Server driver:

Error when preparing a multiple insert query

There are a few things that could cause an error when preparing a multiple insert query in PHP.

How to check if a row exist in the database using PDO?

You can use the rowCount() method of the PDOStatement object to check if a row exists in the database using PDO.

How to properly set up a PDO connection

To set up a PDO connection, you will need to do the following:

In PHP with PDO, how to check the final SQL parametrized query?

In PHP with PDO, you can use the debugDumpParams() method on a prepared statement object to view the final SQL parametrized query.

mysqli or PDO - what are the pros and cons?

mysqli and PDO are both PHP extensions used for interacting with databases.

PDO get the last ID inserted

To get the last inserted ID using PDO, you can use the PDO::lastInsertId() method after inserting a row into the database.

PDO with INSERT INTO through prepared statements

To insert data into a database using PDO and prepared statements, you can use the following steps:

PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused

The error message "SQLSTATE[HY000] [2002] Connection refused" typically indicates that the client was unable to establish a connection to the database server.