MYSQL_ATTR_INIT_COMMAND错误 [英] MYSQL_ATTR_INIT_COMMAND error

查看:69
本文介绍了MYSQL_ATTR_INIT_COMMAND错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Zend Framework的新手,我正在学习如何按照framework.zend网页中的步骤创建应用程序.

I'm new to Zend Framework and I'm learning how to create an application following the steps in the framework.zend webpages.

我对global.php页面有问题.

I have a problem with the global.php page.

我的global.php是:

my global.php is:

return array(
     'db' => array(
         'driver'         => 'Pdo',
         'dsn'            => 'mysql:dbname=zf2tutorial;host=127.0.0.1;charset=utf8',
         'driver_options' => array(
             PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
         ),
     ),
     'service_manager' => array(
         'factories' => array(
             'Zend\Db\Adapter\Adapter'
                     => 'Zend\Db\Adapter\AdapterServiceFactory',
         ),
     ),
 );

我想知道PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"指令的用途,因为如果我在localhost:8080上运行应用程序,它将给我一个错误.

I'd like to know what the instruction PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'" is for, because it gives me an error if I run the application on localhost:8080.

这是错误:Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in C:\DevBox\zfproject\config\autoload\global.php

我可以删除该行吗?如果无法删除它,该如何解决该问题?

Can I remove that line? And If I cannot remove it how can I fix the problem?

我在Windows上,如果删除该行,一切正常,但我认为这不是正确的解决方案.

I'm on windows and everything works if I remove that line but I don't think it's the right solution.

推荐答案

是的,您可以删除该行.

Yes, you can remove that line.

实际上,这只是每一个PHP用户背诵的福音或咒语,而实际上并不知道其含义.它旨在设置默认字符集,该字符集已在DSN中设置(尽管自PHP 5.3.6起有效)

Actually, it's just a some sort of gospel, or mantra, each PHP user recites without actually knowing the meaning. It's intended to set default charset, which is already set in DSN (although effective since PHP 5.3.6)

尽管如此,您也可以在类名后加上反斜杠以解决该问题,从而使PDO类可从任何命名空间中访问.

Nevertheless, you can also perpend a class name with backslash to solve the problem, to make PDO class accessible from within any namespace.

这篇关于MYSQL_ATTR_INIT_COMMAND错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆