php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47224 MYSQL_ATTR_INIT_COMMAND is no longer available
Submitted: 2009-01-27 12:33 UTC Modified: 2009-09-23 21:30 UTC
Votes:41
Avg. Score:4.6 ± 1.0
Reproduced:38 of 39 (97.4%)
Same Version:13 (34.2%)
Same OS:27 (71.1%)
From: contact at joycebabu dot com Assigned: mysql
Status: Closed Package: PDO related
PHP Version: 5.3.0alpha3 OS: Windows
Private report: No CVE-ID:
 [2009-01-27 12:33 UTC] contact at joycebabu dot com
Description:
------------
The constant PDO::MYSQL_ATTR_INIT_COMMAND is not available.

Reproduce code:
---------------
try {
    $pdbo = new PDO("mysql:host=localhost;dbname=test", 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}catch(PDOException $e){
    echo $e->getMessage();
}


Expected result:
----------------
A successful connection to the mysql database

Actual result:
--------------
Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in D:\Projects\Apache\htdocs\mysite.com\httpdocs\include\define-vars.inc.php on line 23

Patches

datasource (last revision 2014-01-17 13:42 UTC) by l dot derusse at primavista-group dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-25 15:35 UTC] jani@php.net
For some reason this (and some other) constants are only available when 
mysqlnd driver is used.
 [2009-05-22 04:06 UTC] christian dot gahlert at web dot de
Hi,

I just had the same problem. It occured because I installed the PDO extension via pecl but forgot to also install PDO_MYSQL.

After I installed the PDO_MYSQL everything was fine.

I hope I could save someone some time :)
Chris
 [2009-06-02 12:15 UTC] daniz at rocketmail dot com
Looking into 

/ext/pdo_mysql/pdo_mysql.c I saw this:

/* {{{ PHP_MINIT_FUNCTION
 */
static PHP_MINIT_FUNCTION(pdo_mysql)
{
#if PDO_USE_MYSQLND
	REGISTER_INI_ENTRIES();
#endif

	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_USE_BUFFERED_QUERY", (long)PDO_MYSQL_ATTR_USE_BUFFERED_QUERY);
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_LOCAL_INFILE", (long)PDO_MYSQL_ATTR_LOCAL_INFILE);	
#ifndef PDO_USE_MYSQLND
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_MAX_BUFFER_SIZE", (long)PDO_MYSQL_ATTR_MAX_BUFFER_SIZE);
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_INIT_COMMAND", (long)PDO_MYSQL_ATTR_INIT_COMMAND);
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_FILE", (long)PDO_MYSQL_ATTR_READ_DEFAULT_FILE);
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_GROUP", (long)PDO_MYSQL_ATTR_READ_DEFAULT_GROUP);
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_COMPRESS", (long)PDO_MYSQL_ATTR_COMPRESS);
#endif
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_DIRECT_QUERY", (long)PDO_MYSQL_ATTR_DIRECT_QUERY);
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_FOUND_ROWS", (long)PDO_MYSQL_ATTR_FOUND_ROWS);
	REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_IGNORE_SPACE", (long)PDO_MYSQL_ATTR_IGNORE_SPACE);

#ifdef PDO_USE_MYSQLND
	pdo_mysqlnd_zval_cache = mysqlnd_palloc_init_cache(PDO_MYSQL_G(cache_size));
#endif
	
	return php_pdo_register_driver(&pdo_mysql_driver);
}



Meaning in short:
if not defined "PDO_USE_MYSQLND" - REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_INIT_COMMAND", (long)PDO_MYSQL_ATTR_INIT_COMMAND);

else don't register that class? Does it's supposed to come from somewhere else? I just moved the init_command into a simple query("SET NAMES utf8"); to get rid of the error.
 [2009-07-02 10:43 UTC] mg at artigo dot pl
A temporary solution is to use INT value (1002) instead of constant.
 [2009-07-17 00:34 UTC] techi at techi dot name
Using 1002 instead of constant does not work either. Using 5.3.0 under 
x64 Windows
 [2009-07-31 06:31 UTC] nitel_defect at yahoo dot com
I subscribe, the 1002 fix does not work: Windows 7 x64, PHP 5.3.0, MySQL 5.1.36
 [2009-08-20 15:20 UTC] emma dot foster-bouz38wu at yopmail dot com
Reproduced with PHP5.3.1 on Windows XP 32bits.
 [2009-08-31 09:38 UTC] andrey@php.net
mysqlnd did not support in 5.3.0 INIT_COMMAND, support is already in svn however and will be part of 5.3.1, but PDO needs to export and use that functionality.
 [2009-09-23 21:30 UTC] uw@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

http://news.php.net/php.cvs/60481
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 14:02:33 2014 UTC