Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion ext/pdo_mysql/mysql_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,36 @@ static zend_result pdo_mysql_check_liveness(pdo_dbh_t *dbh)
}
/* }}} */

/* {{{ proto string PDO::mysqlGetWarningCount()
Returns the number of SQL warnings during the execution of the last statement */
static PHP_METHOD(PDO, mysqlGetWarningCount)
{
pdo_dbh_t *dbh;
pdo_mysql_db_handle *H;

dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;

H = (pdo_mysql_db_handle *)dbh->driver_data;
RETURN_LONG(mysql_warning_count(H->server));
}
/* }}} */

static const zend_function_entry dbh_methods[] = {
PHP_ME(PDO, mysqlGetWarningCount, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};

static const zend_function_entry *pdo_mysql_get_driver_methods(pdo_dbh_t *dbh, int kind)
{
switch (kind) {
case PDO_DBH_DRIVER_METHOD_KIND_DBH:
return dbh_methods;
default:
return NULL;
}
}

/* {{{ pdo_mysql_request_shutdown */
static void pdo_mysql_request_shutdown(pdo_dbh_t *dbh)
{
Expand Down Expand Up @@ -625,7 +655,7 @@ static const struct pdo_dbh_methods mysql_methods = {
pdo_mysql_fetch_error_func,
pdo_mysql_get_attribute,
pdo_mysql_check_liveness,
NULL,
pdo_mysql_get_driver_methods,
pdo_mysql_request_shutdown,
pdo_mysql_in_transaction,
NULL /* get_gc */
Expand Down
22 changes: 22 additions & 0 deletions ext/pdo_mysql/tests/pdo_mysql_get_warning_count.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
MySQL PDO->mysqlGetWarningCount()
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
$db = MySQLPDOTest::factory();
$assertWarnings = function ($db, $q, $count) {
$db->query($q);
printf("Query %s produced %d warnings\n", $q, $db->mysqlGetWarningCount());
};
$assertWarnings($db, 'SELECT 1 = 1', 0);
$assertWarnings($db, 'SELECT 1 = "A"', 1);
?>
--EXPECT--
Query SELECT 1 = 1 produced 0 warnings
Query SELECT 1 = "A" produced 1 warnings