CookieEater
CookieEater

Reputation: 2496

PDO Setting PDO::MYSQL_ATTR_FOUND_ROWS fails

I'm trying to set PDO::MYSQL_ATTR_FOUND_ROWS attribute to true in PDO, but I cannot seem to set it. I am using PHP 5.4.16 and MySQL 5.5.PDO and pdo_mysql both appear in my phpinfo().

Here is how I try to set it to true.

public function __construct () {
    $dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8';
    $this->_db = new PDO($dsn,DB_USER,DB_PASS);

    // The following setAttribute() returns FALSE.
    $this->_db->setAttribute(PDO::MYSQL_ATTR_FOUND_ROWS, TRUE); 
}

I tried to look for every possible settings I can think of. What am I still missing?

Upvotes: 7

Views: 6916

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157918

It seems that PDO::MYSQL_ATTR_FOUND_ROWS is a mysql connection option. Thus, it works only as PDO connection option as well. So, set it up this way

$opt  = array(
    PDO::MYSQL_ATTR_FOUND_ROWS   => TRUE,
    // you may wish to set other options as well
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
);
$this->_db = new PDO($dsn,DB_USER,DB_PASS,$opt);

Upvotes: 19

Related Questions