問(wèn)題描述
如何讓 PDO 適配器在每次連接時(shí)都運(yùn)行 SET NAMES utf8,在 ZendFramework 中.我正在使用 INI 文件來(lái)保存適配器配置數(shù)據(jù).我應(yīng)該在那里添加哪些條目?
How to make PDO adapter run SET NAMES utf8 each time I connect, In ZendFramework. I am using an INI file to save the adapter config data. what entries should I add there?
如果不清楚,我會(huì)在我的項(xiàng)目的 config.ini 文件中尋找正確的語(yǔ)法,而不是在 php 代碼中,因?yàn)槲艺J(rèn)為這部分是配置代碼.
If it wasn't clear, I am looking for the correct syntax to do it in the config.ini file of my project and not in php code, as I regard this part of the configuration code.
推薦答案
Itay,
一個(gè)很好的問(wèn)題.幸運(yùn)的是,答案很簡(jiǎn)單:
A very good question. Fortunately for you the answer is very simple:
database.params.driver_options.1002 = "SET NAMES utf8"
1002 是常量 PDO::MYSQL_ATTR_INIT_COMMAND 的值
1002 is the value of constant PDO::MYSQL_ATTR_INIT_COMMAND
你不能在 config.ini 中使用常量
You can't use the constant in the config.ini
這篇關(guān)于在 ZendFramework 中,如何讓 PDO 每次連接時(shí)都運(yùn)行 SET NAMES utf8的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!