What are the disadvantages of using persistent connection in PDO

In PDO, a connection can be made persistent using the PDO::ATTR_PERSISTENT attribute. According to the php manual – Persistent connections are not closed at the end of the script, but are cached and re-used when another script requests a connection using the same credentials. The persistent connection cache allows you to avoid the overhead of … Read more

PHP PDO: charset, set names?

I had this previously in my normal mysql_* connection: mysql_set_charset(“utf8”,$link); mysql_query(“SET NAMES ‘UTF8′”); Do I need it for the PDO? And where should I have it? $connect = new PDO(“mysql:host=$host;dbname=$db”, $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); 10 Answers 10

Row count with PDO

There are many conflicting statements around. What is the best way to get the row count using PDO in PHP? Before using PDO, I just simply used mysql_num_rows. fetchAll is something I won’t want because I may sometimes be dealing with large datasets, so not good for my use. Do you have any suggestions? 22 … Read more

Can PHP PDO Statements accept the table or column name as parameter?

Why can’t I pass the table name to a prepared PDO statement? $stmt = $dbh->prepare(‘SELECT * FROM :table WHERE 1’); if ($stmt->execute(array(‘:table’ => ‘users’))) { var_dump($stmt->fetchAll()); } Is there another safe way to insert a table name into a SQL query? With safe, I mean that I don’t want to do $sql = “SELECT * … Read more

Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Migration error on Laravel 5.4 with php artisan make:auth [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter tabl e users add unique users_email_unique(email)) [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes … Read more

mysqli or PDO – what are the pros and cons? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for … Read more

PDOException SQLSTATE[HY000] [2002] No such file or directory

I believe that I’ve successfully deployed my (very basic) site to fortrabbit, but as soon as I connect to SSH to run some commands (such as php artisan migrate or php artisan db:seed) I get an error message: [PDOException] SQLSTATE[HY000] [2002] No such file or directory At some point the migration must have worked, because … Read more

Can I bind an array to an IN() condition in a PDO query?

I’m curious to know if it’s possible to bind an array of values to a placeholder using PDO. The use case here is attempting to pass an array of values for use with an IN() condition. I’d like to be able to do something like this: <?php $ids=array(1,2,3,7,8,9); $db = new PDO(…); $stmt = $db->prepare( … Read more