What is the reason for CakePHP to do the query "SET CHARACTER SET utf8" 38 times in a row for a simple find("all") (recursive property default at 0) ?
I use MySQL as database and let's say I create a users table which looks like this:
CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT,
username char(50) UNIQUE,
password char(40),
post_id INT,
created DATETIME,
modified DATETIME,
CONSTRAINT PRIMARY KEY (id),
CONSTRAINT FOREIGN KEY (post_id) REFERENCES posts (id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=INNODB;
and a posts table which looks like this:
CREATE TABLE posts (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(30) NOT NULL,
content TEXT NOT NULL,
CONSTRAINT PRIMARY KEY (id)
) ENGINE=INNODB;
In my users_controller.php, I write in an action:
$log = $this->User->getDataSource()->getLog(false, false);
$this->User->find("all",
array(
'conditions' => array('id' => 3),
'recursive' => 0
));
debug($log);
I haven't tested this with the data above, but showed the tables above because they are similar to my current database. I use 25 tables with engine=innodb.
The debug is an array of 41 queries, where 2 queries retrieves the user and the post. The other 39 queries are identical and looks as follows:
Array
(
[log] => Array
(
[0] => Array
(
[query] => SET CHARACTER SET utf8;
[error] =>
[affected] => 0
[numRows] =>
[took] => 0
)
[1] => Array
(
[query] => SET CHARACTER SET utf8;
[error] =>
[affected] => 0
[numRows] =>
[took] => 0
)
.
.
.
[38] => Array
(
[query] => SET CHARACTER SET utf8;
[error] =>
[affected] => 0
[numRows] =>
[took] => 0
)
Is this supposed to happen? In my config/database.php file, it doesn't matter if I set encoding to 'utf8' or not. I do want 'utf8', but I don't want 38 unnecessary queries.
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'mylogin',
'password' => 'mypassword',
'database' => 'mydatabase',
'encoding' => 'utf8'
);
this sort of thing is expected in debug, cake uses the information to work. when you turn off debug it should all go away
Problem solved. It was a mistake from my part. The constructor in AppModel had the line:
$this->query( "SET CHARACTER SET utf8;" );
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