diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 8917b9b0dc1..375100b3602 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -155,7 +155,8 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */ if (dbh->methods->fetch_err(dbh, stmt, &info)) { zval *item; - if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL) { + if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL + && Z_TYPE_P(item) == IS_LONG) { native_code = Z_LVAL_P(item); } @@ -165,8 +166,10 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */ } } - if (supp) { + if (native_code && supp) { message = strpprintf(0, "SQLSTATE[%s]: %s: " ZEND_LONG_FMT " %s", *pdo_err, msg, native_code, supp); + } else if (supp) { + message = strpprintf(0, "SQLSTATE[%s]: %s: %s", *pdo_err, msg, supp); } else { message = strpprintf(0, "SQLSTATE[%s]: %s", *pdo_err, msg); } diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index d800d65a2df..a5b0a22f205 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -114,6 +114,10 @@ static int pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in if (einfo->errcode) { add_next_index_long(info, einfo->errcode); + } else { + add_next_index_null(info); + } + if (einfo->errmsg) { add_next_index_string(info, einfo->errmsg); } diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 149e1e6b51e..21f4c83807e 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -282,8 +282,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data * ZEND_ATOL(param->paramno, namevar + 1); param->paramno--; } else { - pdo_pgsql_error_stmt_msg( - stmt, PGRES_FATAL_ERROR, "HY093", ZSTR_VAL(param->name)); + pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", ZSTR_VAL(param->name)); return 0; } } @@ -295,8 +294,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data * return 1; } if (!zend_hash_index_exists(stmt->bound_param_map, param->paramno)) { - pdo_pgsql_error_stmt_msg( - stmt, PGRES_FATAL_ERROR, "HY093", "parameter was not defined"); + pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", "parameter was not defined"); return 0; } case PDO_PARAM_EVT_EXEC_POST: diff --git a/ext/pdo_pgsql/tests/bug36727.phpt b/ext/pdo_pgsql/tests/bug36727.phpt index 4c9716d1415..79102ef8bb3 100644 --- a/ext/pdo_pgsql/tests/bug36727.phpt +++ b/ext/pdo_pgsql/tests/bug36727.phpt @@ -19,6 +19,6 @@ var_dump($stmt->bindValue(':test', 1, PDO::PARAM_INT)); echo "Done\n"; ?> --EXPECTF-- -Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: 7 :test in %s on line %d +Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :test in %s on line %d bool(false) Done diff --git a/ext/pdo_pgsql/tests/bug69344.phpt b/ext/pdo_pgsql/tests/bug69344.phpt index e2522653f50..f544518455f 100644 --- a/ext/pdo_pgsql/tests/bug69344.phpt +++ b/ext/pdo_pgsql/tests/bug69344.phpt @@ -39,5 +39,5 @@ $test(); ?> --EXPECT-- -SQLSTATE[HY093]: Invalid parameter number: 7 parameter was not defined +SQLSTATE[HY093]: Invalid parameter number: parameter was not defined SQLSTATE[HY093]: Invalid parameter number: parameter was not defined diff --git a/ext/pdo_pgsql/tests/bug71573.phpt b/ext/pdo_pgsql/tests/bug71573.phpt index d9e4fe75143..e8d13ca84e8 100644 --- a/ext/pdo_pgsql/tests/bug71573.phpt +++ b/ext/pdo_pgsql/tests/bug71573.phpt @@ -18,4 +18,4 @@ $statement->execute([ 'test', 'test', 'test' ]); ?> --EXPECTF-- -Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: 7 parameter was not defined in %s on line %d +Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in %s on line %d