|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51596 Exception when creating database with PDO
Submitted: 2010-04-19 02:40 UTC Modified: 2011-01-04 14:04 UTC
From: foo-script at o2 dot pl Assigned: mysql (profile)
Status: Wont fix Package: PDO related
PHP Version: 5.3.2 OS: Windows XP SP3
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-04-19 02:40 UTC] foo-script at o2 dot pl
A "test script" produced following exception:

exception 'PDOException' with message 'SQLSTATE[HY000]: General error' in L:\Program Files\Apache Software Foundation\Apache2.2\htdocs\readme.php:44 Stack trace: #0 L:\Program Files\Apache Software Foundation\Apache2.2\htdocs\readme.php(44): unknown() #1 {main}

However, database have been successfuly created.

Test script:
	$pdo=new PDO('mysql:host='.$dbHost.';'.'dbname=mysql;'.'port='.$port, 'root', $dbKey, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));

	$result=$pdo->query('CREATE DATABASE test;'); }

Expected result:
In my opinion exception should not be thrown, cause effect is good.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-23 19:03 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2010-04-23 19:09 UTC]
-Status: Assigned +Status: Feedback
 [2010-04-23 19:09 UTC]
Please try using this snapshot:
For Windows:

I can't reproduce it.
 [2011-01-04 14:04 UTC]
-Status: Feedback +Status: Wont fix
 [2011-01-04 14:04 UTC]
That's a matter of the PDO API: what shall happen if init command (or any other statement run as part of object construction/connection establishment) generates an error? I see no bug here. It seems logical to me that the underlying driver code throws an exception in case of a SQL error. Be that desired or not. I'm not aware of any other way to expose that error using todays PDO API.
 [2011-01-04 20:39 UTC] foo-script at o2 dot pl
@nw: This command ran good, I mean everything has been done.
Exception should not be thrown, cause this query has been processed and result was fine.

You wrote: "It seems logical to me that the underlying driver code throws an exception in case of a SQL error". The query I ran doesn't produce any error, neither in MySQL Console, nor in JDBC.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 07:01:31 2024 UTC