php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: foo-script at o2 dot pl
New email:
PHP Version: OS:

 

 [2010-04-19 02:40 UTC] foo-script at o2 dot pl
Description:
------------
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:
---------------
try{
	$pdo=new PDO('mysql:host='.$dbHost.';'.'dbname=mysql;'.'port='.$port, 'root', $dbKey, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));

	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$result=$pdo->query('CREATE DATABASE test;'); }

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I can't reproduce it.
 [2011-01-04 14:04 UTC] uw@php.net
-Status: Feedback +Status: Wont fix
 [2011-01-04 14:04 UTC] uw@php.net
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: Sat Apr 20 02:01:29 2024 UTC