I’ve written a functional login script using MySQL. However, I’ve now been told that it needs to be done using PDO, and I’ve a functional PDO connection: function getConnection() { $userName = ‘**…
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 error reporting. I don’t know how true any of these statements are anymore. My greatest concern in choosing a MySQL
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 while loop works fine
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() later in your code to see
PHP PDO Firebird inserting
I’m new in Firebird but I’d like to write a small script in PHP that reads a CSV file and fills an existing Firebird db with its data. The problem is I don’t really know how to use the autoincrement …
PDO connection works from command line, but not through Apache?
I have a very simple test script: When I execute this script from the command line, it works perfectly: But when I access the exact same script through my web browser, it says: I’ve tried var_dump on the error, and the message is: “SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘db.example.edu’ (13)”. This is puzzling. It’s the exact same
PDO Mysql prepared statement last_insert_id returns wrong value on multi-insert?
I noticed that if I prepare a multi-insert statement and execute it into MySQL via PDO, and then request the last_insert_id, I get the first ID of the multiple inserted rows, not the last one. Specifically: will create these rows on an empty table: But the last_insert_id will return “1”. Is this a known issue or am I doing something
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 php_pdo_mysql.dll,
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. execute will also perform better if you are repeating a
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: