0

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

I have a problem with the global.php page.

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',
         ),
     ),
 );

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.

This is the error: 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?

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

splunk
  • 6,435
  • 17
  • 58
  • 105

1 Answers1

0

Yes, you can remove that line.

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)

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

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345