Skip to content

Commit 64fca5c

Browse files
committed
Fix bug GH-1 (mysqli_sql_exception->sqlstate is inaccessible)
1 parent 345f46f commit 64fca5c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

ext/mysqli/mysqli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ PHP_MINIT_FUNCTION(mysqli)
568568
mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, spl_ce_RuntimeException);
569569
mysqli_exception_class_entry->ce_flags |= ZEND_ACC_FINAL;
570570
zend_declare_property_long(mysqli_exception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED);
571-
zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PROTECTED);
571+
zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PUBLIC);
572572

573573
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, class_mysqli_driver_methods);
574574
ce = mysqli_driver_class_entry;

ext/mysqli/tests/bugGH1.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #GH-1 mysqli_sql_exception->sqlstate is inaccessible
3+
--EXTENSIONS--
4+
mysqli
5+
--SKIPIF--
6+
<?php
7+
require_once "connect.inc";
8+
require_once 'skipifconnectfailure.inc';
9+
?>
10+
--FILE--
11+
<?php
12+
require 'connect.inc';
13+
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
14+
15+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
16+
17+
try {
18+
$link->query("stuff");
19+
} catch (mysqli_sql_exception $exception) {
20+
var_dump($exception->sqlstate);
21+
}
22+
23+
?>
24+
--EXPECT--
25+
string(5) "42000"

0 commit comments

Comments
 (0)