Skip to content

Commit

Permalink
Merge branch 'PHP-5.6'
Browse files Browse the repository at this point in the history
Conflicts:
	NEWS
	ext/mysqlnd/mysqlnd_result.c
  • Loading branch information
faizshukri committed Apr 10, 2014
2 parents c2ce0df + d3f390a commit 6828437
Show file tree
Hide file tree
Showing 43 changed files with 1,663 additions and 374 deletions.
10 changes: 5 additions & 5 deletions ext/mysql/php_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifndef MYSQL_USE_MYSQLND
mysql->conn = mysql_init(NULL);
#else
mysql->conn = mysql_init(persistent);
mysql->conn = mysqlnd_init(MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA, persistent);
#endif

if (connect_timeout != -1) {
Expand All @@ -886,7 +886,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifndef MYSQL_USE_MYSQLND
if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
#else
if (mysqlnd_connect(mysql->conn, host, user, passwd, passwd_len, NULL, 0, port, socket, client_flags TSRMLS_CC) == NULL)
if (mysqlnd_connect(mysql->conn, host, user, passwd, passwd_len, NULL, 0, port, socket, client_flags, MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA TSRMLS_CC) == NULL)
#endif
{
/* Populate connect error globals so that the error functions can read them */
Expand Down Expand Up @@ -934,7 +934,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifndef MYSQL_USE_MYSQLND
if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
#else
if (mysqlnd_connect(mysql->conn, host, user, passwd, passwd_len, NULL, 0, port, socket, client_flags TSRMLS_CC) == NULL)
if (mysqlnd_connect(mysql->conn, host, user, passwd, passwd_len, NULL, 0, port, socket, client_flags, MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA TSRMLS_CC) == NULL)
#endif
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Link to server lost, unable to reconnect");
Expand Down Expand Up @@ -996,7 +996,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifndef MYSQL_USE_MYSQLND
mysql->conn = mysql_init(NULL);
#else
mysql->conn = mysql_init(persistent);
mysql->conn = mysqlnd_init(MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA, persistent);
#endif
if (!mysql->conn) {
MySG(connect_error) = estrdup("OOM");
Expand All @@ -1013,7 +1013,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifndef MYSQL_USE_MYSQLND
if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
#else
if (mysqlnd_connect(mysql->conn, host, user, passwd, passwd_len, NULL, 0, port, socket, client_flags TSRMLS_CC) == NULL)
if (mysqlnd_connect(mysql->conn, host, user, passwd, passwd_len, NULL, 0, port, socket, client_flags, MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA TSRMLS_CC) == NULL)
#endif
{
/* Populate connect error globals so that the error functions can read them */
Expand Down
1 change: 1 addition & 0 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ PHP_MINIT_FUNCTION(mysqli)
REGISTER_LONG_CONSTANT("MYSQLI_USE_RESULT", MYSQLI_USE_RESULT, CONST_CS | CONST_PERSISTENT);
#if defined (MYSQLI_USE_MYSQLND)
REGISTER_LONG_CONSTANT("MYSQLI_ASYNC", MYSQLI_ASYNC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("MYSQLI_STORE_RESULT_COPY_DATA", MYSQLI_STORE_RESULT_COPY_DATA, CONST_CS | CONST_PERSISTENT);
#endif

/* for mysqli_fetch_assoc */
Expand Down
16 changes: 11 additions & 5 deletions ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS)
We create always persistent, as if the user want to connecto
to p:somehost, we can't convert the handle then
*/
if (!(mysql->mysql = mysql_init(TRUE)))
if (!(mysql->mysql = mysqlnd_init(MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA, TRUE)))
#endif
{
efree(mysql);
Expand Down Expand Up @@ -2605,21 +2605,27 @@ PHP_FUNCTION(mysqli_stmt_sqlstate)
}
/* }}} */

/* {{{ proto object mysqli_store_result(object link)
/* {{{ proto object mysqli_store_result(object link [, flags])
Buffer result set on client */
PHP_FUNCTION(mysqli_store_result)
{
MY_MYSQL *mysql;
MYSQL_RES *result;
zval *mysql_link;
MYSQLI_RESOURCE *mysqli_resource;
long flags = 0;

if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {

if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &mysql_link, mysqli_link_class_entry, &flags) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

if (!(result = mysql_store_result(mysql->mysql))) {
#if MYSQLI_USE_MYSQLND
result = flags & MYSQLI_STORE_RESULT_COPY_DATA? mysqlnd_store_result_ofs(mysql->mysql) : mysqlnd_store_result(mysql->mysql);
#else
result = mysql_store_result(mysql->mysql);
#endif
if (!result) {
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
RETURN_FALSE;
}
Expand Down
15 changes: 13 additions & 2 deletions ext/mysqli/mysqli_fe.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_rollback, 0, 0, 0)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()


ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_store_result, 0, 0, 1)
MYSQLI_ZEND_ARG_OBJ_INFO_LINK()
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_store_result, 0, 0, 0)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()


ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_change_user, 0, 0, 4)
MYSQLI_ZEND_ARG_OBJ_INFO_LINK()
ZEND_ARG_INFO(0, user)
Expand Down Expand Up @@ -498,7 +509,7 @@ const zend_function_entry mysqli_functions[] = {
PHP_FE(mysqli_sqlstate, arginfo_mysqli_only_link)
PHP_FE(mysqli_ssl_set, arginfo_mysqli_ssl_set)
PHP_FE(mysqli_stat, arginfo_mysqli_only_link)
PHP_FE(mysqli_store_result, arginfo_mysqli_only_link)
PHP_FE(mysqli_store_result, arginfo_mysqli_store_result)
PHP_FE(mysqli_thread_id, arginfo_mysqli_only_link)
PHP_FE(mysqli_thread_safe, arginfo_mysqli_no_params)
PHP_FE(mysqli_use_result, arginfo_mysqli_only_link)
Expand Down Expand Up @@ -568,7 +579,7 @@ const zend_function_entry mysqli_link_methods[] = {
PHP_FALIAS(ssl_set, mysqli_ssl_set, arginfo_class_mysqli_ssl_set)
PHP_FALIAS(stat, mysqli_stat, arginfo_mysqli_no_params)
PHP_FALIAS(stmt_init, mysqli_stmt_init, arginfo_mysqli_no_params)
PHP_FALIAS(store_result, mysqli_store_result, arginfo_mysqli_no_params)
PHP_FALIAS(store_result, mysqli_store_result, arginfo_class_store_result)
PHP_FALIAS(thread_safe, mysqli_thread_safe, arginfo_mysqli_no_params)
PHP_FALIAS(use_result, mysqli_use_result, arginfo_mysqli_no_params)
PHP_FALIAS(refresh,mysqli_refresh, arginfo_class_mysqli_refresh)
Expand Down
15 changes: 10 additions & 5 deletions ext/mysqli/mysqli_nonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
#if !defined(MYSQLI_USE_MYSQLND)
if (!(mysql->mysql = mysql_init(NULL))) {
#else
if (!(mysql->mysql = mysqlnd_init(persistent))) {
if (!(mysql->mysql = mysqlnd_init(MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA, persistent))) {
#endif
goto err;
}
Expand All @@ -240,7 +240,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname, port, socket, flags) == NULL)
#else
if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname, dbname_len,
port, socket, flags TSRMLS_CC) == NULL)
port, socket, flags, MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA TSRMLS_CC) == NULL)
#endif
{
/* Save error messages - for mysqli_connect_error() & mysqli_connect_errno() */
Expand Down Expand Up @@ -575,7 +575,7 @@ PHP_FUNCTION(mysqli_query)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty query");
RETURN_FALSE;
}
if ((resultmode & ~MYSQLI_ASYNC) != MYSQLI_USE_RESULT && (resultmode & ~MYSQLI_ASYNC) != MYSQLI_STORE_RESULT) {
if ((resultmode & ~MYSQLI_ASYNC) != MYSQLI_USE_RESULT && (resultmode & ~(MYSQLI_ASYNC | MYSQLI_STORE_RESULT_COPY_DATA)) != MYSQLI_STORE_RESULT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for resultmode");
RETURN_FALSE;
}
Expand Down Expand Up @@ -609,9 +609,14 @@ PHP_FUNCTION(mysqli_query)
RETURN_TRUE;
}

switch (resultmode) {
switch (resultmode & ~(MYSQLI_ASYNC | MYSQLI_STORE_RESULT_COPY_DATA)) {
case MYSQLI_STORE_RESULT:
result = mysql_store_result(mysql->mysql);
#ifdef MYSQLI_USE_MYSQLND
if (resultmode & MYSQLI_STORE_RESULT_COPY_DATA) {
result = mysqlnd_store_result_ofs(mysql->mysql);
} else
#endif
result = mysql_store_result(mysql->mysql);
break;
case MYSQLI_USE_RESULT:
result = mysql_use_result(mysql->mysql);
Expand Down
2 changes: 2 additions & 0 deletions ext/mysqli/mysqli_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
#define MYSQLI_USE_RESULT 1
#ifdef MYSQLI_USE_MYSQLND
#define MYSQLI_ASYNC 8
#define MYSQLI_STORE_RESULT_COPY_DATA 16
#else
/* libmysql */
#define MYSQLI_ASYNC 0
#define MYSQLI_STORE_RESULT_OFS 0
#endif

/* for mysqli_fetch_assoc */
Expand Down
4 changes: 3 additions & 1 deletion ext/mysqli/tests/bug66043.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ require_once('skipifconnectfailure.inc');
--FILE--
<?php
require 'connect.inc';
$db = new mysqli($host, $user, $passwd, 'mysql');
if (!$db = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}

$stmt = $db->stmt_init();
$stmt->prepare("SELECT User FROM user WHERE password=\"\"");
Expand Down
5 changes: 3 additions & 2 deletions ext/mysqli/tests/bug66762.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ require_once('skipifconnectfailure.inc');
<?php
require_once("connect.inc");

$mysqli = new mysqli($host, $user, $passwd, $db);
if (!$mysqli = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}

$read_stmt = $mysqli->prepare("SELECT 1");

var_dump($read_stmt->bind_result($data));

unset($mysqli);
var_dump($read_stmt->bind_result($data));

?>
done!
--EXPECT--
Expand Down
92 changes: 52 additions & 40 deletions ext/mysqli/tests/mysqli_change_user.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,79 +32,91 @@ require_once('skipifconnectfailure.inc');
printf("[006] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);

if (false !== ($tmp = mysqli_change_user($link, $user . '_unknown_really', $passwd . 'non_empty', $db)))
if (false !== ($tmp = @mysqli_change_user($link, $user . '_unknown_really', $passwd . 'non_empty', $db)))
printf("[007] Expecting false, got %s/%s\n", gettype($tmp), $tmp);

if (false !== ($tmp = mysqli_change_user($link, $user, $passwd . '_unknown_really', $db)))
printf("[008] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[008] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);

if (false !== ($tmp = mysqli_change_user($link, $user, $passwd, $db . '_unknown_really')))
if (false !== ($tmp = @mysqli_change_user($link, $user, $passwd . '_unknown_really', $db)))
printf("[009] Expecting false, got %s/%s\n", gettype($tmp), $tmp);

if (!mysqli_query($link, 'SET @mysqli_change_user_test_var=1'))
printf("[010] Failed to set test variable: [%d] %s\n", mysqli_errno($link), mysqli_error($link));

if (!$res = mysqli_query($link, 'SELECT @mysqli_change_user_test_var AS test_var'))
printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);
if (1 != $tmp['test_var'])
printf("[012] Cannot set test variable\n");

if (true !== ($tmp = mysqli_change_user($link, $user, $passwd, $db)))
printf("[013] Expecting true, got %s/%s\n", gettype($tmp), $tmp);

if (!$res = mysqli_query($link, 'SELECT database() AS dbname, user() AS user'))
printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);

if (substr($tmp['user'], 0, strlen($user)) !== $user)
printf("[015] Expecting user %s, got user() %s\n", $user, $tmp['user']);
if ($tmp['dbname'] != $db)
printf("[016] Expecting database %s, got database() %s\n", $db, $tmp['dbname']);
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[010] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);

if (!$res = mysqli_query($link, 'SELECT @mysqli_change_user_test_var AS test_var'))
printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);
if (NULL !== $tmp['test_var'])
printf("[019] Test variable is still set!\n");
if (false !== ($tmp = @mysqli_change_user($link, $user, $passwd, $db . '_unknown_really')))
printf("[011] Expecting false, got %s/%s\n", gettype($tmp), $tmp);

mysqli_close($link);

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
printf("[020] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
printf("[012] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);
}

if (false !== ($tmp = mysqli_change_user($link, str_repeat('user', 16384), str_repeat('pass', 16384), str_repeat('dbase', 16384))))
printf("[021] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
if (false !== ($tmp = @mysqli_change_user($link, str_repeat('user', 16384), str_repeat('pass', 16384), str_repeat('dbase', 16384))))
printf("[013] Expecting false, got %s/%s\n", gettype($tmp), $tmp);

mysqli_close($link);

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);
}

/* silent protocol change if no db which requires workaround in mysqlnd/libmysql
(empty db = no db send with COM_CHANGE_USER) */
if (true !== ($tmp = mysqli_change_user($link, $user, $passwd, "")))
printf("[023] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
printf("[015] Expecting true, got %s/%s\n", gettype($tmp), $tmp);

if (!$res = mysqli_query($link, 'SELECT database() AS dbname, user() AS user'))
printf("[024] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);

if ($tmp['dbname'] != "")
printf("[025] Expecting database '', got database() '%s'\n", $tmp['dbname']);
printf("[017] Expecting database '', got database() '%s'\n", $tmp['dbname']);

mysqli_close($link);

if (NULL !== ($tmp = @mysqli_change_user($link, $user, $passwd, $db)))
printf("[026] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[019] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);

if (!mysqli_query($link, 'SET @mysqli_change_user_test_var=1'))
printf("[020] Failed to set test variable: [%d] %s\n", mysqli_errno($link), mysqli_error($link));

if (!$res = mysqli_query($link, 'SELECT @mysqli_change_user_test_var AS test_var'))
printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);
if (1 != $tmp['test_var'])
printf("[022] Cannot set test variable\n");

if (true !== ($tmp = mysqli_change_user($link, $user, $passwd, $db)))
printf("[023] Expecting true, got %s/%s\n", gettype($tmp), $tmp);

if (!$res = mysqli_query($link, 'SELECT database() AS dbname, user() AS user'))
printf("[024] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);

if (substr($tmp['user'], 0, strlen($user)) !== $user)
printf("[025] Expecting user %s, got user() %s\n", $user, $tmp['user']);
if ($tmp['dbname'] != $db)
printf("[026] Expecting database %s, got database() %s\n", $db, $tmp['dbname']);

if (!$res = mysqli_query($link, 'SELECT @mysqli_change_user_test_var AS test_var'))
printf("[027] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);
if (NULL !== $tmp['test_var'])
printf("[028] Test variable is still set!\n");

print "done!";
?>
Expand Down
44 changes: 44 additions & 0 deletions ext/mysqli/tests/mysqli_change_user_new.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
mysqli_change_user(), MySQL 5.6+
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket));

if (mysqli_get_server_version($link) < 50600)
die("SKIP For MySQL >= 5.6.0");
?>
--FILE--
<?php
require_once("connect.inc");

$tmp = NULL;
$link = NULL;

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);

/* Pre 5.6: link remains useable */
if (false !== ($tmp = @mysqli_change_user($link, $user . '_unknown_really', $passwd . 'non_empty', $db)))
printf("[002] Expecting false, got %s/%s\n", gettype($tmp), $tmp);

if (!$res = mysqli_query($link, 'SELECT 1 AS _one'))
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

var_dump($res->fetch_assoc());

print "done!";
?>
--EXPECTF--
Warning: mysqli_query(): MySQL server has gone away in %s on line %d

Warning: mysqli_query(): Error reading result set's header in %s on line %d
[003] [2006] MySQL server has gone away

Fatal error: Call to a member function fetch_assoc() on a non-object in %s on line %d
Loading

0 comments on commit 6828437

Please sign in to comment.