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?
PDO is an acronym for PHP Data Objects. PDO is a lean, consistent way to access databases. This means developers can write portable code much easier. PDO is not an abstraction layer like PearDB.
PDO (PHP Data Objects) is a general database abstraction layer with support for MySQL among many other databases. It provides prepared statements, and significant flexibility in how data is returned.
$pdo = new PDO($dsn, $user, $passwd); A new PDO object is created. We pass the constructor the data source name and the user name and password. The PDO class represents a connection between PHP and a database server.
Pdo ( Portable Data Object ) needs to be installed if it is not done before. For windows platform go to control panel > Add remove program ( or Programs and features ) > Select your PHP installation and click Change. If you are installing PHP fresh then in the setup wizard you can select PDO from Extensions link.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With