-1

I am working on a zend framework 2 application, and I am working with port 8080. My main probleme in the begining is that i couldn't retrieve or add data from database in the views (probably, a probleme with connection with database). It didn't show any error, but data couldn't be retrieved or added. I tried to specify the port in global.php:

<?php

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

After that, I got this error:

Warning: PDO::__construct(): MySQL server has gone away in

I looked for a solution, and I found one. I commented a line in php.ini:

extension=php_pdo_mysql.dll

It solved the probleme, but now Im stuck with another probleme:

Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in C:\wamp\www\pizza\config\autoload\global.php on line 18

I found some suggestions on how to fix this probleme by Linux command:

 apt-get install php5-mysql /etc/init.d/apache2 restart 

But i want a solution for windows 7, or any other you may find useful. Thanks for your time.

edigu
  • 9,878
  • 5
  • 57
  • 80
user3720155
  • 13
  • 1
  • 5
  • if you replace it with the representing integer 1002 does it work? Also i do not see the port specified in your global.php. I think you get that error because you comented that line in php.ini – dixromos98 Aug 11 '14 at 09:47
  • the port=8080 is specified, and like a said if i uncomment the line the "MySQL server has gone away" error occcurs. could you please tell me what should i replace with 1002 – user3720155 Aug 11 '14 at 09:59
  • then i suggest you to solve "MySQL server has gone away" error and consider this discussion http://stackoverflow.com/questions/2232150/pdo-mysql-server-has-gone-away – dixromos98 Aug 11 '14 at 10:03

1 Answers1

1

Unfortunately, it seems like you found bad advice on two occasions. You're getting the Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' error because by commenting out php_pdo_mysql.dll you effectively disabled the MySQL extension. So uncomment that line - you definitely want that there.

You mentioned that you're "working with port 8080" but it's not clear if your ZF2 application is running on port 8080, or if you're running MySQL on that port (which would be non-standard). You said you tried to specify this port in your global.php configuration file, but the port is nowhere to be seen in the configuration you posted.

The "MySQL server has gone away" error means the MySQL connection is timing out. Usually this is caused by PHP scripts that run for a very long time (>30 seconds) without touching the DB connection. This is unlikely to happen in a standard web application, so we'd need more info about what led up to this error in order to help you.

You also said that you "couldn't retrieve or add data from database in the views". If this is still the case, there must be an error somewhere, even if it's not being shown to you. So check the relevant error logs and your error settings.

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69