Skip to content

Instantly share code, notes, and snippets.

@Norbyte
Created September 24, 2014 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Norbyte/d0ddf2361b74bf784a33 to your computer and use it in GitHub Desktop.
Save Norbyte/d0ddf2361b74bf784a33 to your computer and use it in GitHub Desktop.
PDO exception fix
diff --git a/hphp/runtime/ext/pdo_driver.cpp b/hphp/runtime/ext/pdo_driver.cpp
index 8ed0a16..a208793 100644
--- a/hphp/runtime/ext/pdo_driver.cpp
+++ b/hphp/runtime/ext/pdo_driver.cpp
@@ -18,6 +18,7 @@
#include "hphp/runtime/ext/pdo_driver.h"
#include "hphp/runtime/ext/pdo_sqlite.h"
#include "hphp/runtime/ext/pdo_mysql.h"
#include "hphp/runtime/ext/std/ext_std_variable.h"
namespace HPHP {
@@ -29,6 +30,9 @@ PDODriverMap PDODriver::s_drivers;
// We will have to list them all here for proper static initialization.
static PDOSqlite s_sqlite_driver;
static PDOMySql s_mysql_driver;
+
+const StaticString s_general_error_code("HY000");
PDODriver::PDODriver(const char *name) : m_name(name) {
s_drivers[name] = this;
@@ -49,7 +53,12 @@ PDOConnection *PDODriver::createConnection(const String& datasource,
}
if (!conn->create(options)) {
+ Array err;
+ bool hasError = conn->fetchErr(nullptr, err);
delete conn;
+ if (hasError && !err.empty()) {
+ throw_pdo_exception(s_general_error_code, uninit_null(), "[%ld]: %s", err[0].toInt64(), err[1].toString().data());
+ }
return NULL;
}
return conn;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment