PDO::exec() or PDO::query()?

请求翻译

I used to have this as one of the options (4th param) passed to PDO constructor:

$aOptions[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES utf8";

But just found that it does not work on certain php versions on Windows (does not work in 5.3) due to some bug.

Now I need to run SET NAMES utf8 using either $pdo->exec("SET NAMES utf8");

or $pdo->query("SET NAMES utf8");

right after the instantiating the pdo object. So, which one should I use - exec() or query()?

2个回答