Skip to content

Tag: pdo

PDO MySQL: Use PDO::ATTR_EMULATE_PREPARES or not?

This is what I’ve read so far about PDO::ATTR_EMULATE_PREPARES: PDO’s prepare emulation is better for performance since MySQL’s native prepare bypasses the query cache. MySQL’s native prepare is better for security (preventing SQL Injection). MySQL’s native prepare is better for …

Resetting array pointer in PDO results

I’m having trouble moving from MySQL SELECT methods to PDO methods. I want to iterate through a fetched array twice, both times starting with row zero. In MySQL I would use: Using PDO methods, I’m not sure how to accomplish the same thing. The code below is how I am trying to do this. The first wh…

How to get database name in PDO?

Is there a function or constant within PDO that stores the database name (the testdb value) ? I did a var_dump on $dbh and cant find anything… Answer You could use the setAttribute() (essentially a key value pair) method to store the database name when you set it up initially, then use the getAttribute(…

PHP PDO extension not working on IIS

I have a script which uses __autoload() to load classes (stupid, I know, this is old code I used to use for fun / testing), and it seems to be trying to autoload PDO. This leads me to believe that it’s not finding the PDO class it should be. I have checked php.ini and php_pdo.dll is enabled, along with …

PDO’s query vs execute

Are they both do the same thing, only differently? Is there any difference besides using prepare between and ? Answer query runs a standard SQL statement without parameterized data. execute runs a prepared statement which allows you to bind parameters to avoid the need to escape or quote the parameters. execu…

PHP PDO: charset, set names?

I had this previously in my normal mysql_* connection: Do I need it for the PDO? And where should I have it? Answer You’ll have it in your connection string like: HOWEVER, prior to PHP 5.3.6, the charset option was ignored. If you’re running an older version of PHP, you must do it like this: