summaryrefslogtreecommitdiff
path: root/ext/mysqli/mysqli_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mysqli/mysqli_api.c')
-rw-r--r--ext/mysqli/mysqli_api.c705
1 files changed, 318 insertions, 387 deletions
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index 9896ab8eda..d1e0634dc7 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -33,8 +31,10 @@
#include "mysqli_priv.h"
#include "ext/mysqlnd/mysql_float_to_double.h"
+#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
+
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
/* {{{ mysqli_tx_cor_options_to_string */
static void mysqli_tx_cor_options_to_string(const MYSQL * const conn, smart_str * str, const uint32_t mode)
{
@@ -93,7 +93,7 @@ mysqli_escape_string_for_tx_name_in_comment(const char * const name)
{
*p_copy++ = v;
} else if (warned == FALSE) {
- php_error_docref(NULL, E_WARNING, "Transaction name truncated. Must be only [0-9A-Za-z\\-_=]+");
+ php_error_docref(NULL, E_WARNING, "Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, \"\\\", \"-\", \"_\", and \"=\" characters");
warned = TRUE;
}
++p_orig;
@@ -135,8 +135,7 @@ static int mysqli_commit_or_rollback_libmysql(MYSQL * conn, zend_bool commit, co
/* }}} */
#endif
-/* {{{ proto mixed mysqli_affected_rows(object link)
- Get number of affected rows in previous MySQL operation */
+/* {{{ Get number of affected rows in previous MySQL operation */
PHP_FUNCTION(mysqli_affected_rows)
{
MY_MYSQL *mysql;
@@ -144,7 +143,7 @@ PHP_FUNCTION(mysqli_affected_rows)
my_ulonglong rc;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -157,8 +156,7 @@ PHP_FUNCTION(mysqli_affected_rows)
}
/* }}} */
-/* {{{ proto bool mysqli_autocommit(object link, bool mode)
- Turn auto commit on or of */
+/* {{{ Turn auto commit on or of */
PHP_FUNCTION(mysqli_autocommit)
{
MY_MYSQL *mysql;
@@ -166,7 +164,7 @@ PHP_FUNCTION(mysqli_autocommit)
zend_bool automode;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ob", &mysql_link, mysqli_link_class_entry, &automode) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -181,8 +179,7 @@ PHP_FUNCTION(mysqli_autocommit)
/* {{{ mysqli_stmt_bind_param_do_bind */
#ifndef MYSQLI_USE_MYSQLND
static
-int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned int num_vars,
- zval *args, unsigned int start, const char * const types)
+int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *args, const char * const types, unsigned int num_extra_args)
{
int i, ofs;
MYSQL_BIND *bind;
@@ -197,7 +194,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in
bind = (MYSQL_BIND *) ecalloc(num_vars, sizeof(MYSQL_BIND));
ofs = 0;
- for (i = start; i < argc; i++) {
+ for (i = 0; i < num_vars; i++) {
zval *param;
if (Z_ISREF(args[i])) {
param = Z_REFVAL(args[i]);
@@ -234,7 +231,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in
break;
default:
- php_error_docref(NULL, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i+1);
+ zend_argument_value_error(num_extra_args, "must only contain the \"b\", \"d\", \"i\", \"s\" type specifiers");
rc = 1;
goto end_1;
}
@@ -250,7 +247,7 @@ end_1:
stmt->param.vars = safe_emalloc(num_vars, sizeof(zval), 0);
for (i = 0; i < num_vars; i++) {
if (bind[i].buffer_type != MYSQL_TYPE_LONG_BLOB) {
- ZVAL_COPY(&stmt->param.vars[i], &args[i+start]);
+ ZVAL_COPY(&stmt->param.vars[i], &args[i]);
} else {
ZVAL_UNDEF(&stmt->param.vars[i]);
}
@@ -262,22 +259,21 @@ end_1:
}
#else
static
-int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned int num_vars,
- zval *args, unsigned int start, const char * const types)
+int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *args, const char * const types, unsigned int num_extra_args)
{
unsigned int i;
MYSQLND_PARAM_BIND *params;
enum_func_status ret = FAIL;
/* If no params -> skip binding and return directly */
- if (argc == start) {
+ if (num_vars == 0) {
return PASS;
}
params = mysqlnd_stmt_alloc_param_bind(stmt->stmt);
if (!params) {
goto end;
}
- for (i = 0; i < (argc - start); i++) {
+ for (i = 0; i < num_vars; i++) {
zend_uchar type;
switch (types[i]) {
case 'd': /* Double */
@@ -297,13 +293,12 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned in
type = MYSQL_TYPE_VAR_STRING;
break;
default:
- /* We count parameters from 1 */
- php_error_docref(NULL, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[i], i + start + 1);
+ zend_argument_value_error(num_extra_args, "must only contain the \"b\", \"d\", \"i\", \"s\" type specifiers");
ret = FAIL;
mysqlnd_stmt_free_param_bind(stmt->stmt, params);
goto end;
}
- ZVAL_COPY_VALUE(&params[i].zv, &args[i + start]);
+ ZVAL_COPY_VALUE(&params[i].zv, &args[i]);
params[i].type = type;
}
ret = mysqlnd_stmt_bind_param(stmt->stmt, params);
@@ -314,69 +309,40 @@ end:
#endif
/* }}} */
-/* {{{ proto bool mysqli_stmt_bind_param(object stmt, string types, mixed variable [,mixed ...])
- Bind variables to a prepared statement as parameters */
+/* {{{ Bind variables to a prepared statement as parameters */
PHP_FUNCTION(mysqli_stmt_bind_param)
{
zval *args;
- int argc = ZEND_NUM_ARGS();
- int num_vars;
- int start = 2;
+ int argc;
MY_STMT *stmt;
zval *mysql_stmt;
char *types;
size_t types_len;
- zend_ulong rc;
-
- /* calculate and check number of parameters */
- if (argc < 2) {
- /* there has to be at least one pair */
- WRONG_PARAM_COUNT;
- }
- if (zend_parse_method_parameters((getThis()) ? 1:2, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry,
- &types, &types_len) == FAILURE) {
- return;
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os*", &mysql_stmt, mysqli_stmt_class_entry, &types, &types_len, &args, &argc) == FAILURE) {
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
- num_vars = argc - 1;
- if (getThis()) {
- start = 1;
- } else {
- /* ignore handle parameter in procedural interface*/
- --num_vars;
- }
if (!types_len) {
- php_error_docref(NULL, E_WARNING, "Invalid type or no types specified");
- RETURN_FALSE;
+ zend_argument_value_error(ERROR_ARG_POS(2), "cannot be empty");
+ RETURN_THROWS();
}
- if (types_len != (size_t)(argc - start)) {
+ if (types_len != (size_t) argc) {
/* number of bind variables doesn't match number of elements in type definition string */
- php_error_docref(NULL, E_WARNING, "Number of elements in type definition string doesn't match number of bind variables");
- RETURN_FALSE;
+ zend_argument_count_error("The number of elements in the type definition string must match the number of bind variables");
+ RETURN_THROWS();
}
if (types_len != mysql_stmt_param_count(stmt->stmt)) {
- php_error_docref(NULL, E_WARNING, "Number of variables doesn't match number of parameters in prepared statement");
- RETURN_FALSE;
+ zend_argument_count_error("The number of variables must match the number of parameters in the prepared statement");
+ RETURN_THROWS();
}
- args = safe_emalloc(argc, sizeof(zval), 0);
-
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- zend_wrong_param_count();
- rc = 1;
- } else {
- rc = mysqli_stmt_bind_param_do_bind(stmt, argc, num_vars, args, start, types);
- MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
- }
-
- efree(args);
-
- RETURN_BOOL(!rc);
+ RETVAL_BOOL(!mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, getThis() ? 1 : 2));
+ MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
}
/* }}} */
@@ -404,7 +370,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc)
int size;
char *p = emalloc(size= var_cnt * (sizeof(char) + sizeof(VAR_BUFFER)));
stmt->result.buf = (VAR_BUFFER *) p;
- stmt->result.is_null = p + var_cnt * sizeof(VAR_BUFFER);
+ stmt->result.is_null = (my_bool *) (p + var_cnt * sizeof(VAR_BUFFER));
memset(p, 0, size);
}
@@ -462,9 +428,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc)
break;
case MYSQL_TYPE_LONGLONG:
-#if MYSQL_VERSION_ID > 50002 || defined(MYSQLI_USE_MYSQLND)
case MYSQL_TYPE_BIT:
-#endif
stmt->result.buf[ofs].type = IS_STRING;
stmt->result.buf[ofs].buflen = sizeof(my_ulonglong);
stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
@@ -493,12 +457,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc)
case MYSQL_TYPE_NEWDECIMAL:
#endif
{
-#if MYSQL_VERSION_ID >= 50107
- /* Changed to my_bool in MySQL 5.1. See MySQL Bug #16144 */
my_bool tmp;
-#else
- zend_ulong tmp = 0;
-#endif
stmt->result.buf[ofs].type = IS_STRING;
/*
If the user has called $stmt->store_result() then we have asked
@@ -579,8 +538,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc)
#endif
/* }}} */
-/* {{{ proto bool mysqli_stmt_bind_result(object stmt, mixed var [,mixed ...])
- Bind variables to a prepared statement for result storage */
+/* {{{ Bind variables to a prepared statement for result storage */
PHP_FUNCTION(mysqli_stmt_bind_result)
{
zval *args;
@@ -590,14 +548,14 @@ PHP_FUNCTION(mysqli_stmt_bind_result)
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O+", &mysql_stmt, mysqli_stmt_class_entry, &args, &argc) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
if ((uint32_t)argc != mysql_stmt_field_count(stmt->stmt)) {
- php_error_docref(NULL, E_WARNING, "Number of bind variables doesn't match number of fields in prepared statement");
- RETURN_FALSE;
+ zend_argument_count_error("Number of bind variables doesn't match number of fields in prepared statement");
+ RETURN_THROWS();
}
rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc);
@@ -605,8 +563,7 @@ PHP_FUNCTION(mysqli_stmt_bind_result)
}
/* }}} */
-/* {{{ proto bool mysqli_change_user(object link, string user, string password, string database)
- Change logged-in user of the active connection */
+/* {{{ Change logged-in user of the active connection */
PHP_FUNCTION(mysqli_change_user)
{
MY_MYSQL *mysql;
@@ -614,20 +571,20 @@ PHP_FUNCTION(mysqli_change_user)
char *user, *password, *dbname;
size_t user_len, password_len, dbname_len;
zend_ulong rc;
-#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+#ifndef MYSQLI_USE_MYSQLND
MY_CHARSET_INFO old_charset;
#endif
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Osss!", &mysql_link, mysqli_link_class_entry, &user, &user_len, &password, &password_len, &dbname, &dbname_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+#ifndef MYSQLI_USE_MYSQLND
mysql_get_character_set_info(mysql->mysql, &old_charset);
#endif
-#if defined(MYSQLI_USE_MYSQLND)
+#ifdef MYSQLI_USE_MYSQLND
rc = mysqlnd_change_user_ex(mysql->mysql, user, password, dbname, FALSE, (size_t) password_len);
#else
rc = mysql_change_user(mysql->mysql, user, password, dbname);
@@ -637,7 +594,7 @@ PHP_FUNCTION(mysqli_change_user)
if (rc) {
RETURN_FALSE;
}
-#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
+#ifndef MYSQLI_USE_MYSQLND
if (mysql_get_server_version(mysql->mysql) < 50123L) {
/*
Request the current charset, or it will be reset to the system one.
@@ -652,8 +609,7 @@ PHP_FUNCTION(mysqli_change_user)
}
/* }}} */
-/* {{{ proto string mysqli_character_set_name(object link)
- Returns the name of the character set used for this connection */
+/* {{{ Returns the name of the character set used for this connection */
PHP_FUNCTION(mysqli_character_set_name)
{
MY_MYSQL *mysql;
@@ -661,7 +617,7 @@ PHP_FUNCTION(mysqli_character_set_name)
const char *cs_name;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -686,12 +642,12 @@ void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status)
if ((le = zend_hash_find_ptr(&EG(persistent_list), mysql->hash_key)) != NULL) {
if (le->type == php_le_pmysqli()) {
mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
-#if defined(MYSQLI_USE_MYSQLND)
+#ifdef MYSQLI_USE_MYSQLND
mysqlnd_end_psession(mysql->mysql);
#endif
if (MyG(rollback_on_cached_plink) &&
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
mysqli_commit_or_rollback_libmysql(mysql->mysql, FALSE, TRANS_COR_NO_OPT, NULL))
#else
FAIL == mysqlnd_rollback(mysql->mysql, TRANS_COR_NO_OPT, NULL))
@@ -713,15 +669,14 @@ void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status)
}
/* }}} */
-/* {{{ proto bool mysqli_close(object link)
- Close connection */
+/* {{{ Close connection */
PHP_FUNCTION(mysqli_close)
{
zval *mysql_link;
MY_MYSQL *mysql;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_INITIALIZED);
@@ -735,22 +690,21 @@ PHP_FUNCTION(mysqli_close)
}
/* }}} */
-/* {{{ proto bool mysqli_commit(object link[, int flags [, string name ]])
- Commit outstanding actions and close transaction */
+/* {{{ Commit outstanding actions and close transaction */
PHP_FUNCTION(mysqli_commit)
{
MY_MYSQL *mysql;
zval *mysql_link;
zend_long flags = TRANS_COR_NO_OPT;
char * name = NULL;
- size_t name_len = 0;
+ size_t name_len;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|ls", &mysql_link, mysqli_link_class_entry, &flags, &name, &name_len) == FAILURE) {
- return;
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|ls!", &mysql_link, mysqli_link_class_entry, &flags, &name, &name_len) == FAILURE) {
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
if (mysqli_commit_or_rollback_libmysql(mysql->mysql, TRUE, flags, name)) {
#else
if (FAIL == mysqlnd_commit(mysql->mysql, flags, name)) {
@@ -762,8 +716,7 @@ PHP_FUNCTION(mysqli_commit)
}
/* }}} */
-/* {{{ proto bool mysqli_data_seek(object result, int offset)
- Move internal result pointer */
+/* {{{ Move internal result pointer */
PHP_FUNCTION(mysqli_data_seek)
{
MYSQL_RES *result;
@@ -771,17 +724,26 @@ PHP_FUNCTION(mysqli_data_seek)
zend_long offset;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
- return;
+ RETURN_THROWS();
+ }
+
+ if (offset < 0) {
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
if (mysqli_result_is_unbuffered(result)) {
- php_error_docref(NULL, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
- RETURN_FALSE;
+ if (getThis()) {
+ zend_throw_error(NULL, "mysqli_result::data_seek() cannot be used in MYSQLI_USE_RESULT mode");
+ } else {
+ zend_throw_error(NULL, "mysqli_data_seek() cannot be used in MYSQLI_USE_RESULT mode");
+ }
+ RETURN_THROWS();
}
- if (offset < 0 || (uint64_t)offset >= mysql_num_rows(result)) {
+ if ((uint64_t)offset >= mysql_num_rows(result)) {
RETURN_FALSE;
}
@@ -790,15 +752,14 @@ PHP_FUNCTION(mysqli_data_seek)
}
/* }}} */
-/* {{{ proto void mysqli_debug(string debug)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_debug)
{
char *debug;
size_t debug_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &debug, &debug_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
mysql_debug(debug);
@@ -806,39 +767,36 @@ PHP_FUNCTION(mysqli_debug)
}
/* }}} */
-/* {{{ proto bool mysqli_dump_debug_info(object link)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_dump_debug_info)
{
MY_MYSQL *mysql;
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
- RETURN_BOOL(!mysql_dump_debug_info(mysql->mysql))
+ RETURN_BOOL(!mysql_dump_debug_info(mysql->mysql));
}
/* }}} */
-/* {{{ proto int mysqli_errno(object link)
- Returns the numerical value of the error message from previous MySQL operation */
+/* {{{ Returns the numerical value of the error message from previous MySQL operation */
PHP_FUNCTION(mysqli_errno)
{
MY_MYSQL *mysql;
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
RETURN_LONG(mysql_errno(mysql->mysql));
}
/* }}} */
-/* {{{ proto string mysqli_error(object link)
- Returns the text of the error message from previous MySQL operation */
+/* {{{ Returns the text of the error message from previous MySQL operation */
PHP_FUNCTION(mysqli_error)
{
MY_MYSQL *mysql;
@@ -846,7 +804,7 @@ PHP_FUNCTION(mysqli_error)
const char *err;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
err = mysql_error(mysql->mysql);
@@ -856,8 +814,7 @@ PHP_FUNCTION(mysqli_error)
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_execute(object stmt)
- Execute a prepared statement */
+/* {{{ Execute a prepared statement */
PHP_FUNCTION(mysqli_stmt_execute)
{
MY_STMT *stmt;
@@ -867,7 +824,7 @@ PHP_FUNCTION(mysqli_stmt_execute)
#endif
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -902,7 +859,7 @@ PHP_FUNCTION(mysqli_stmt_execute)
switch (stmt->stmt->params[i].buffer_type) {
case MYSQL_TYPE_VAR_STRING:
if (!try_convert_to_string(param)) {
- return;
+ RETURN_THROWS();
}
stmt->stmt->params[i].buffer = Z_STRVAL_P(param);
@@ -947,12 +904,11 @@ void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
zval *mysql_stmt;
unsigned int i;
zend_ulong ret;
- unsigned int uval;
my_ulonglong llval;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -984,8 +940,8 @@ void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
&& (stmt->stmt->fields[i].flags & UNSIGNED_FLAG))
{
/* unsigned int (11) */
- uval= *(unsigned int *) stmt->result.buf[i].val;
-#if SIZEOF_ZEND_LONG==4
+#if SIZEOF_ZEND_LONG == 4
+ unsigned int uval = *(unsigned int *) stmt->result.buf[i].val;
if (uval > INT_MAX) {
char *tmp, *p;
int j = 10;
@@ -1028,12 +984,9 @@ void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
}
case IS_STRING:
if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_LONGLONG
-#if MYSQL_VERSION_ID > 50002
|| stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT
-#endif
) {
my_bool uns = (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? 1:0;
-#if MYSQL_VERSION_ID > 50002
if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT) {
switch (stmt->result.buf[i].output_len) {
case 8:llval = (my_ulonglong) bit_uint8korr(stmt->result.buf[i].val);break;
@@ -1045,9 +998,7 @@ void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
case 2:llval = (my_ulonglong) bit_uint2korr(stmt->result.buf[i].val);break;
case 1:llval = (my_ulonglong) uint1korr(stmt->result.buf[i].val);break;
}
- } else
-#endif
- {
+ } else {
llval= *(my_ulonglong *) stmt->result.buf[i].val;
}
#if SIZEOF_ZEND_LONG==8
@@ -1069,14 +1020,10 @@ void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
ZEND_TRY_ASSIGN_REF_LONG(result, llval);
}
} else {
-#if defined(MYSQL_DATA_TRUNCATED) && MYSQL_VERSION_ID > 50002
if (ret == MYSQL_DATA_TRUNCATED && *(stmt->stmt->bind[i].error) != 0) {
/* result was truncated */
ZEND_TRY_ASSIGN_REF_STRINGL(result, stmt->result.buf[i].val, stmt->stmt->bind[i].buffer_length);
} else {
-#else
- {
-#endif
ZEND_TRY_ASSIGN_REF_STRINGL(result, stmt->result.buf[i].val, stmt->result.buf[i].output_len);
}
}
@@ -1121,7 +1068,7 @@ void mysqli_stmt_fetch_mysqlnd(INTERNAL_FUNCTION_PARAMETERS)
zend_bool fetched_anything;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -1137,11 +1084,10 @@ void mysqli_stmt_fetch_mysqlnd(INTERNAL_FUNCTION_PARAMETERS)
#endif
/* }}} */
-/* {{{ proto mixed mysqli_stmt_fetch(object stmt)
- Fetch results from a prepared statement into the bound variables */
+/* {{{ Fetch results from a prepared statement into the bound variables */
PHP_FUNCTION(mysqli_stmt_fetch)
{
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAM_PASSTHRU);
#else
mysqli_stmt_fetch_mysqlnd(INTERNAL_FUNCTION_PARAM_PASSTHRU);
@@ -1179,8 +1125,7 @@ static void php_add_field_properties(zval *value, const MYSQL_FIELD *field)
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_field(object result)
- Get column information from a result and return as an object */
+/* {{{ Get column information from a result and return as an object */
PHP_FUNCTION(mysqli_fetch_field)
{
MYSQL_RES *result;
@@ -1188,7 +1133,7 @@ PHP_FUNCTION(mysqli_fetch_field)
const MYSQL_FIELD *field;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
@@ -1202,8 +1147,7 @@ PHP_FUNCTION(mysqli_fetch_field)
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_fields(object result)
- Return array of objects containing field meta-data */
+/* {{{ Return array of objects containing field meta-data */
PHP_FUNCTION(mysqli_fetch_fields)
{
MYSQL_RES *result;
@@ -1213,7 +1157,7 @@ PHP_FUNCTION(mysqli_fetch_fields)
unsigned int i, num_fields;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
@@ -1232,8 +1176,7 @@ PHP_FUNCTION(mysqli_fetch_fields)
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_field_direct(object result, int offset)
- Fetch meta-data for a single field */
+/* {{{ Fetch meta-data for a single field */
PHP_FUNCTION(mysqli_fetch_field_direct)
{
MYSQL_RES *result;
@@ -1242,14 +1185,19 @@ PHP_FUNCTION(mysqli_fetch_field_direct)
zend_long offset;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
- return;
+ RETURN_THROWS();
+ }
+
+ if (offset < 0) {
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
- if (offset < 0 || offset >= (zend_long) mysql_num_fields(result)) {
- php_error_docref(NULL, E_WARNING, "Field offset is invalid for resultset");
- RETURN_FALSE;
+ if (offset >= (zend_long) mysql_num_fields(result)) {
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be less than the number of fields for this result set");
+ RETURN_THROWS();
}
if (!(field = mysql_fetch_field_direct(result,offset))) {
@@ -1261,25 +1209,25 @@ PHP_FUNCTION(mysqli_fetch_field_direct)
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_lengths(object result)
- Get the length of each output in a result */
+/* {{{ Get the length of each output in a result */
PHP_FUNCTION(mysqli_fetch_lengths)
{
MYSQL_RES *result;
zval *mysql_result;
unsigned int i, num_fields;
-#if defined(MYSQLI_USE_MYSQLND)
+#ifdef MYSQLI_USE_MYSQLND
const size_t *ret;
#else
const zend_ulong *ret;
#endif
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
+ // TODO Warning?
if (!(ret = mysql_fetch_lengths(result))) {
RETURN_FALSE;
}
@@ -1293,24 +1241,21 @@ PHP_FUNCTION(mysqli_fetch_lengths)
}
/* }}} */
-/* {{{ proto array mysqli_fetch_row(object result)
- Get a result row as an enumerated array */
+/* {{{ Get a result row as an enumerated array */
PHP_FUNCTION(mysqli_fetch_row)
{
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_NUM, 0);
}
/* }}} */
-/* {{{ proto int mysqli_field_count(object link)
- Fetch the number of fields returned by the last query for the given link
-*/
+/* {{{ Fetch the number of fields returned by the last query for the given link */
PHP_FUNCTION(mysqli_field_count)
{
MY_MYSQL *mysql;
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -1318,9 +1263,7 @@ PHP_FUNCTION(mysqli_field_count)
}
/* }}} */
-/* {{{ proto int mysqli_field_seek(object result, int fieldnr)
- Set result pointer to a specified field offset
-*/
+/* {{{ Set result pointer to a specified field offset */
PHP_FUNCTION(mysqli_field_seek)
{
MYSQL_RES *result;
@@ -1328,13 +1271,19 @@ PHP_FUNCTION(mysqli_field_seek)
zend_long fieldnr;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &fieldnr) == FAILURE) {
- return;
+ RETURN_THROWS();
}
+
+ if (fieldnr < 0) {
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+ RETURN_THROWS();
+ }
+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
- if (fieldnr < 0 || (uint32_t)fieldnr >= mysql_num_fields(result)) {
- php_error_docref(NULL, E_WARNING, "Invalid field offset");
- RETURN_FALSE;
+ if ((uint32_t)fieldnr >= mysql_num_fields(result)) {
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be less than the number of fields for this result set");
+ RETURN_THROWS();
}
mysql_field_seek(result, fieldnr);
@@ -1342,15 +1291,14 @@ PHP_FUNCTION(mysqli_field_seek)
}
/* }}} */
-/* {{{ proto int mysqli_field_tell(object result)
- Get current field offset of result pointer */
+/* {{{ Get current field offset of result pointer */
PHP_FUNCTION(mysqli_field_tell)
{
MYSQL_RES *result;
zval *mysql_result;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
@@ -1358,15 +1306,14 @@ PHP_FUNCTION(mysqli_field_tell)
}
/* }}} */
-/* {{{ proto void mysqli_free_result(object result)
- Free query result memory for the given result handle */
+/* {{{ Free query result memory for the given result handle */
PHP_FUNCTION(mysqli_free_result)
{
MYSQL_RES *result;
zval *mysql_result;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
@@ -1375,10 +1322,21 @@ PHP_FUNCTION(mysqli_free_result)
}
/* }}} */
-/* {{{ proto string mysqli_get_client_info(void)
- Get MySQL client info */
+/* {{{ Get MySQL client info */
PHP_FUNCTION(mysqli_get_client_info)
{
+ if (getThis()) {
+ if (zend_parse_parameters_none() == FAILURE) {
+ RETURN_THROWS();
+ }
+ } else {
+ zval *mysql_link;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O!", &mysql_link, mysqli_link_class_entry) == FAILURE) {
+ RETURN_THROWS();
+ }
+ }
+
const char * info = mysql_get_client_info();
if (info) {
RETURN_STRING(info);
@@ -1386,26 +1344,28 @@ PHP_FUNCTION(mysqli_get_client_info)
}
/* }}} */
-/* {{{ proto int mysqli_get_client_version(void)
- Get MySQL client info */
+/* {{{ Get MySQL client info */
PHP_FUNCTION(mysqli_get_client_version)
{
+ if (zend_parse_parameters_none() == FAILURE) {
+ RETURN_THROWS();
+ }
+
RETURN_LONG((zend_long)mysql_get_client_version());
}
/* }}} */
-/* {{{ proto string mysqli_get_host_info(object link)
- Get MySQL host info */
+/* {{{ Get MySQL host info */
PHP_FUNCTION(mysqli_get_host_info)
{
MY_MYSQL *mysql;
zval *mysql_link = NULL;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
RETURN_STRING((mysql->mysql->host_info) ? mysql->mysql->host_info : "");
#else
RETURN_STRING((mysql->mysql->data->host_info) ? mysql->mysql->data->host_info : "");
@@ -1413,50 +1373,43 @@ PHP_FUNCTION(mysqli_get_host_info)
}
/* }}} */
-/* {{{ proto int mysqli_get_proto_info(object link)
- Get MySQL protocol information */
+/* {{{ Get MySQL protocol information */
PHP_FUNCTION(mysqli_get_proto_info)
{
MY_MYSQL *mysql;
zval *mysql_link = NULL;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
RETURN_LONG(mysql_get_proto_info(mysql->mysql));
}
/* }}} */
-/* {{{ proto string mysqli_get_server_info(object link)
- Get MySQL server info */
+/* {{{ Get MySQL server info */
PHP_FUNCTION(mysqli_get_server_info)
{
MY_MYSQL *mysql;
zval *mysql_link = NULL;
- const char *info;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
- info = mysql_get_server_info(mysql->mysql);
- if (info) {
- RETURN_STRING(info);
- }
+ RETURN_STRING(mysql_get_server_info(mysql->mysql));
}
/* }}} */
-/* {{{ proto int mysqli_get_server_version(object link)
- Return the MySQL version for the server referenced by the given link */
+/* {{{ Return the MySQL version for the server referenced by the given link */
PHP_FUNCTION(mysqli_get_server_version)
{
MY_MYSQL *mysql;
zval *mysql_link = NULL;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -1464,8 +1417,7 @@ PHP_FUNCTION(mysqli_get_server_version)
}
/* }}} */
-/* {{{ proto string mysqli_info(object link)
- Get information about the most recent query */
+/* {{{ Get information about the most recent query */
PHP_FUNCTION(mysqli_info)
{
MY_MYSQL *mysql;
@@ -1473,7 +1425,7 @@ PHP_FUNCTION(mysqli_info)
const char *info;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -1490,17 +1442,21 @@ void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_method)
MYSQLI_RESOURCE *mysqli_resource;
MY_MYSQL *mysql;
+ if (zend_parse_parameters_none() == FAILURE) {
+ RETURN_THROWS();
+ }
+
if (is_method && (Z_MYSQLI_P(getThis()))->ptr) {
return;
}
mysql = (MY_MYSQL *)ecalloc(1, sizeof(MY_MYSQL));
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
if (!(mysql->mysql = mysql_init(NULL)))
#else
/*
- We create always persistent, as if the user want to connecto
+ We create always persistent, as if the user want to connect
to p:somehost, we can't convert the handle then
*/
if (!(mysql->mysql = mysqlnd_init(MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA, TRUE)))
@@ -1522,24 +1478,14 @@ void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_method)
}
/* }}} */
-/* {{{ proto resource mysqli_init(void)
- Initialize mysqli and return a resource for use with mysql_real_connect */
+/* {{{ Initialize mysqli and return a resource for use with mysql_real_connect */
PHP_FUNCTION(mysqli_init)
{
php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU, FALSE);
}
/* }}} */
-/* {{{ proto resource mysqli::init(void)
- Initialize mysqli and return a resource for use with mysql_real_connect */
-PHP_FUNCTION(mysqli_init_method)
-{
- php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU, TRUE);
-}
-/* }}} */
-
-/* {{{ proto mixed mysqli_insert_id(object link)
- Get the ID generated from the previous INSERT operation */
+/* {{{ Get the ID generated from the previous INSERT operation */
PHP_FUNCTION(mysqli_insert_id)
{
MY_MYSQL *mysql;
@@ -1547,7 +1493,7 @@ PHP_FUNCTION(mysqli_insert_id)
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
rc = mysql_insert_id(mysql->mysql);
@@ -1555,8 +1501,7 @@ PHP_FUNCTION(mysqli_insert_id)
}
/* }}} */
-/* {{{ proto bool mysqli_kill(object link, int processid)
- Kill a mysql process on the server */
+/* {{{ Kill a mysql process on the server */
PHP_FUNCTION(mysqli_kill)
{
MY_MYSQL *mysql;
@@ -1564,15 +1509,16 @@ PHP_FUNCTION(mysqli_kill)
zend_long processid;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_link, mysqli_link_class_entry, &processid) == FAILURE) {
- return;
+ RETURN_THROWS();
}
- MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
if (processid <= 0) {
- php_error_docref(NULL, E_WARNING, "processid should have positive value");
- RETURN_FALSE;
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than 0");
+ RETURN_THROWS();
}
+ MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
+
if (mysql_kill(mysql->mysql, processid)) {
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
RETURN_FALSE;
@@ -1581,15 +1527,14 @@ PHP_FUNCTION(mysqli_kill)
}
/* }}} */
-/* {{{ proto bool mysqli_more_results(object link)
- check if there any more query results from a multi query */
+/* {{{ check if there any more query results from a multi query */
PHP_FUNCTION(mysqli_more_results)
{
MY_MYSQL *mysql;
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -1597,14 +1542,13 @@ PHP_FUNCTION(mysqli_more_results)
}
/* }}} */
-/* {{{ proto bool mysqli_next_result(object link)
- read next result from multi_query */
+/* {{{ read next result from multi_query */
PHP_FUNCTION(mysqli_next_result) {
MY_MYSQL *mysql;
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -1616,16 +1560,16 @@ PHP_FUNCTION(mysqli_next_result) {
}
/* }}} */
-#if defined(HAVE_STMT_NEXT_RESULT) && defined(MYSQLI_USE_MYSQLND)
-/* {{{ proto bool mysqli_stmt_more_results(object link)
- check if there any more query results from a multi query */
+/* TODO: Make these available without mysqlnd */
+#if defined(MYSQLI_USE_MYSQLND)
+/* {{{ check if there any more query results from a multi query */
PHP_FUNCTION(mysqli_stmt_more_results)
{
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -1633,14 +1577,13 @@ PHP_FUNCTION(mysqli_stmt_more_results)
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_next_result(object link)
- read next result from multi_query */
+/* {{{ read next result from multi_query */
PHP_FUNCTION(mysqli_stmt_next_result) {
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -1653,15 +1596,14 @@ PHP_FUNCTION(mysqli_stmt_next_result) {
/* }}} */
#endif
-/* {{{ proto int mysqli_num_fields(object result)
- Get number of fields in result */
+/* {{{ Get number of fields in result */
PHP_FUNCTION(mysqli_num_fields)
{
MYSQL_RES *result;
zval *mysql_result;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
@@ -1669,21 +1611,20 @@ PHP_FUNCTION(mysqli_num_fields)
}
/* }}} */
-/* {{{ proto mixed mysqli_num_rows(object result)
- Get number of rows in result */
+/* {{{ Get number of rows in result */
PHP_FUNCTION(mysqli_num_rows)
{
MYSQL_RES *result;
zval *mysql_result;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
if (mysqli_result_is_unbuffered_and_not_everything_is_fetched(result)) {
- php_error_docref(NULL, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
- RETURN_LONG(0);
+ zend_throw_error(NULL, "mysqli_num_rows() cannot be used in MYSQLI_USE_RESULT mode");
+ RETURN_THROWS();
}
MYSQLI_RETURN_LONG_INT(mysql_num_rows(result));
@@ -1708,7 +1649,7 @@ static int mysqli_options_get_option_zval_type(int option)
case MYSQL_OPT_LOCAL_INFILE:
case MYSQL_OPT_NAMED_PIPE:
#ifdef MYSQL_OPT_PROTOCOL
- case MYSQL_OPT_PROTOCOL:
+ case MYSQL_OPT_PROTOCOL:
#endif /* MySQL 4.1.0 */
case MYSQL_OPT_READ_TIMEOUT:
case MYSQL_OPT_WRITE_TIMEOUT:
@@ -1754,8 +1695,7 @@ static int mysqli_options_get_option_zval_type(int option)
}
/* }}} */
-/* {{{ proto bool mysqli_options(object link, int flags, mixed values)
- Set options */
+/* {{{ Set options */
PHP_FUNCTION(mysqli_options)
{
MY_MYSQL *mysql;
@@ -1767,11 +1707,11 @@ PHP_FUNCTION(mysqli_options)
int expected_type;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Olz", &mysql_link, mysqli_link_class_entry, &mysql_option, &mysql_value) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_INITIALIZED);
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
if(mysql_option == MYSQL_OPT_LOCAL_INFILE) {
RETURN_FALSE;
@@ -1783,7 +1723,7 @@ PHP_FUNCTION(mysqli_options)
switch (expected_type) {
case IS_STRING:
if (!try_convert_to_string(mysql_value)) {
- return;
+ RETURN_THROWS();
}
break;
case IS_LONG:
@@ -1810,8 +1750,7 @@ PHP_FUNCTION(mysqli_options)
}
/* }}} */
-/* {{{ proto bool mysqli_ping(object link)
- Ping a server connection or reconnect if there is no connection */
+/* {{{ Ping a server connection or reconnect if there is no connection */
PHP_FUNCTION(mysqli_ping)
{
MY_MYSQL *mysql;
@@ -1819,7 +1758,7 @@ PHP_FUNCTION(mysqli_ping)
zend_long rc;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
rc = mysql_ping(mysql->mysql);
@@ -1829,8 +1768,7 @@ PHP_FUNCTION(mysqli_ping)
}
/* }}} */
-/* {{{ proto mixed mysqli_prepare(object link, string query)
- Prepare a SQL statement for execution */
+/* {{{ Prepare a SQL statement for execution */
PHP_FUNCTION(mysqli_prepare)
{
MY_MYSQL *mysql;
@@ -1841,11 +1779,11 @@ PHP_FUNCTION(mysqli_prepare)
MYSQLI_RESOURCE *mysqli_resource;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os",&mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
if (mysql->mysql->status == MYSQL_STATUS_GET_RESULT) {
php_error_docref(NULL, E_WARNING, "All data must be fetched before a new statement prepare takes place");
RETURN_FALSE;
@@ -1857,7 +1795,7 @@ PHP_FUNCTION(mysqli_prepare)
if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) {
if (mysql_stmt_prepare(stmt->stmt, query, query_len)) {
/* mysql_stmt_close() clears errors, so we have to store them temporarily */
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
char last_error[MYSQL_ERRMSG_SIZE];
char sqlstate[SQLSTATE_LENGTH+1];
unsigned int last_errno;
@@ -1875,7 +1813,7 @@ PHP_FUNCTION(mysqli_prepare)
stmt->stmt = NULL;
/* restore error messages */
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
mysql->mysql->net.last_errno = last_errno;
memcpy(mysql->mysql->net.last_error, last_error, MYSQL_ERRMSG_SIZE);
memcpy(mysql->mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH+1);
@@ -1913,16 +1851,14 @@ PHP_FUNCTION(mysqli_prepare)
}
/* }}} */
-/* {{{ proto bool mysqli_real_connect(object link [,string hostname [,string username [,string passwd [,string dbname [,int port [,string socket [,int flags]]]]]]])
- Open a connection to a mysql server */
+/* {{{ Open a connection to a mysql server */
PHP_FUNCTION(mysqli_real_connect)
{
mysqli_common_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, TRUE, FALSE);
}
/* }}} */
-/* {{{ proto bool mysqli_real_query(object link, string query)
- Binary-safe version of mysql_query() */
+/* {{{ Binary-safe version of mysql_query() */
PHP_FUNCTION(mysqli_real_query)
{
MY_MYSQL *mysql;
@@ -1931,7 +1867,7 @@ PHP_FUNCTION(mysqli_real_query)
size_t query_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -1957,8 +1893,6 @@ PHP_FUNCTION(mysqli_real_query)
mysql_real_escape_string(mysql, to, from, length)
#endif
-/* {{{ proto string mysqli_real_escape_string(object link, string escapestr)
- Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection */
PHP_FUNCTION(mysqli_real_escape_string) {
MY_MYSQL *mysql;
zval *mysql_link = NULL;
@@ -1967,7 +1901,7 @@ PHP_FUNCTION(mysqli_real_escape_string) {
zend_string *newstr;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &mysql_link, mysqli_link_class_entry, &escapestr, &escapestr_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -1977,10 +1911,8 @@ PHP_FUNCTION(mysqli_real_escape_string) {
RETURN_NEW_STR(newstr);
}
-/* }}} */
-/* {{{ proto bool mysqli_rollback(object link)
- Undo actions from current transaction */
+/* {{{ Undo actions from current transaction */
PHP_FUNCTION(mysqli_rollback)
{
MY_MYSQL *mysql;
@@ -1989,12 +1921,12 @@ PHP_FUNCTION(mysqli_rollback)
char * name = NULL;
size_t name_len = 0;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|ls", &mysql_link, mysqli_link_class_entry, &flags, &name, &name_len) == FAILURE) {
- return;
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|ls!", &mysql_link, mysqli_link_class_entry, &flags, &name, &name_len) == FAILURE) {
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
if (mysqli_commit_or_rollback_libmysql(mysql->mysql, FALSE, flags, name)) {
#else
if (FAIL == mysqlnd_rollback(mysql->mysql, flags, name)) {
@@ -2006,8 +1938,7 @@ PHP_FUNCTION(mysqli_rollback)
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_send_long_data(object stmt, int param_nr, string data)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_stmt_send_long_data)
{
MY_STMT *stmt;
@@ -2017,14 +1948,16 @@ PHP_FUNCTION(mysqli_stmt_send_long_data)
size_t data_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ols", &mysql_stmt, mysqli_stmt_class_entry, &param_nr, &data, &data_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
+
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
if (param_nr < 0) {
- php_error_docref(NULL, E_WARNING, "Invalid parameter number");
- RETURN_FALSE;
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+ RETURN_THROWS();
}
+
if (mysql_stmt_send_long_data(stmt->stmt, param_nr, data, data_len)) {
RETURN_FALSE;
}
@@ -2032,8 +1965,7 @@ PHP_FUNCTION(mysqli_stmt_send_long_data)
}
/* }}} */
-/* {{{ proto string|int|false mysqli_stmt_affected_rows(object stmt)
- Return the number of rows affected in the last query for the given link. */
+/* {{{ Return the number of rows affected in the last query for the given link. */
PHP_FUNCTION(mysqli_stmt_affected_rows)
{
MY_STMT *stmt;
@@ -2041,7 +1973,7 @@ PHP_FUNCTION(mysqli_stmt_affected_rows)
my_ulonglong rc;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2053,15 +1985,14 @@ PHP_FUNCTION(mysqli_stmt_affected_rows)
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_close(object stmt)
- Close statement */
+/* {{{ Close statement */
PHP_FUNCTION(mysqli_stmt_close)
{
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2073,8 +2004,7 @@ PHP_FUNCTION(mysqli_stmt_close)
}
/* }}} */
-/* {{{ proto void mysqli_stmt_data_seek(object stmt, int offset)
- Move internal result pointer */
+/* {{{ Move internal result pointer */
PHP_FUNCTION(mysqli_stmt_data_seek)
{
MY_STMT *stmt;
@@ -2082,11 +2012,12 @@ PHP_FUNCTION(mysqli_stmt_data_seek)
zend_long offset;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_stmt, mysqli_stmt_class_entry, &offset) == FAILURE) {
- return;
+ RETURN_THROWS();
}
+
if (offset < 0) {
- php_error_docref(NULL, E_WARNING, "Offset must be positive");
- RETURN_FALSE;
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2095,15 +2026,14 @@ PHP_FUNCTION(mysqli_stmt_data_seek)
}
/* }}} */
-/* {{{ proto int mysqli_stmt_field_count(object stmt) {
- Return the number of result columns for the given statement */
+/* {{{ Return the number of result columns for the given statement */
PHP_FUNCTION(mysqli_stmt_field_count)
{
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2111,15 +2041,14 @@ PHP_FUNCTION(mysqli_stmt_field_count)
}
/* }}} */
-/* {{{ proto void mysqli_stmt_free_result(object stmt)
- Free stored result memory for the given statement handle */
+/* {{{ Free stored result memory for the given statement handle */
PHP_FUNCTION(mysqli_stmt_free_result)
{
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2128,8 +2057,7 @@ PHP_FUNCTION(mysqli_stmt_free_result)
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_insert_id(object stmt)
- Get the ID generated from the previous INSERT operation */
+/* {{{ Get the ID generated from the previous INSERT operation */
PHP_FUNCTION(mysqli_stmt_insert_id)
{
MY_STMT *stmt;
@@ -2137,7 +2065,7 @@ PHP_FUNCTION(mysqli_stmt_insert_id)
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
rc = mysql_stmt_insert_id(stmt->stmt);
@@ -2145,15 +2073,14 @@ PHP_FUNCTION(mysqli_stmt_insert_id)
}
/* }}} */
-/* {{{ proto int mysqli_stmt_param_count(object stmt)
- Return the number of parameter for the given statement */
+/* {{{ Return the number of parameter for the given statement */
PHP_FUNCTION(mysqli_stmt_param_count)
{
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2161,15 +2088,14 @@ PHP_FUNCTION(mysqli_stmt_param_count)
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_reset(object stmt)
- reset a prepared statement */
+/* {{{ reset a prepared statement */
PHP_FUNCTION(mysqli_stmt_reset)
{
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2181,8 +2107,7 @@ PHP_FUNCTION(mysqli_stmt_reset)
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_num_rows(object stmt)
- Return the number of rows in statements result set */
+/* {{{ Return the number of rows in statements result set */
PHP_FUNCTION(mysqli_stmt_num_rows)
{
MY_STMT *stmt;
@@ -2190,7 +2115,7 @@ PHP_FUNCTION(mysqli_stmt_num_rows)
my_ulonglong rc;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2200,8 +2125,7 @@ PHP_FUNCTION(mysqli_stmt_num_rows)
}
/* }}} */
-/* {{{ proto bool mysqli_select_db(object link, string dbname)
- Select a MySQL database */
+/* {{{ Select a MySQL database */
PHP_FUNCTION(mysqli_select_db)
{
MY_MYSQL *mysql;
@@ -2210,7 +2134,7 @@ PHP_FUNCTION(mysqli_select_db)
size_t dbname_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &mysql_link, mysqli_link_class_entry, &dbname, &dbname_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -2222,8 +2146,7 @@ PHP_FUNCTION(mysqli_select_db)
}
/* }}} */
-/* {{{ proto string mysqli_sqlstate(object link)
- Returns the SQLSTATE error from previous MySQL operation */
+/* {{{ Returns the SQLSTATE error from previous MySQL operation */
PHP_FUNCTION(mysqli_sqlstate)
{
MY_MYSQL *mysql;
@@ -2231,7 +2154,7 @@ PHP_FUNCTION(mysqli_sqlstate)
const char *state;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
state = mysql_sqlstate(mysql->mysql);
@@ -2241,8 +2164,7 @@ PHP_FUNCTION(mysqli_sqlstate)
}
/* }}} */
-/* {{{ proto bool mysqli_ssl_set(object link ,string key ,string cert ,string ca ,string capath ,string cipher])
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_ssl_set)
{
MY_MYSQL *mysql;
@@ -2251,7 +2173,7 @@ PHP_FUNCTION(mysqli_ssl_set)
size_t ssl_parm_len[5], i;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Osssss", &mysql_link, mysqli_link_class_entry, &ssl_parm[0], &ssl_parm_len[0], &ssl_parm[1], &ssl_parm_len[1], &ssl_parm[2], &ssl_parm_len[2], &ssl_parm[3], &ssl_parm_len[3], &ssl_parm[4], &ssl_parm_len[4]) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_INITIALIZED);
@@ -2267,24 +2189,23 @@ PHP_FUNCTION(mysqli_ssl_set)
}
/* }}} */
-/* {{{ proto mixed mysqli_stat(object link)
- Get current system status */
+/* {{{ Get current system status */
PHP_FUNCTION(mysqli_stat)
{
MY_MYSQL *mysql;
zval *mysql_link;
-#if defined(MYSQLI_USE_MYSQLND)
+#ifdef MYSQLI_USE_MYSQLND
zend_string *stat;
#else
char *stat;
#endif
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
if ((stat = (char *)mysql_stat(mysql->mysql)))
{
RETURN_STRING(stat);
@@ -2300,8 +2221,7 @@ PHP_FUNCTION(mysqli_stat)
/* }}} */
-/* {{{ proto bool mysqli_refresh(object link, int options)
- Flush tables or caches, or reset replication server information */
+/* {{{ Flush tables or caches, or reset replication server information */
PHP_FUNCTION(mysqli_refresh)
{
MY_MYSQL *mysql;
@@ -2309,7 +2229,7 @@ PHP_FUNCTION(mysqli_refresh)
zend_long options;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_link, mysqli_link_class_entry, &options) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_INITIALIZED);
#ifdef MYSQLI_USE_MYSQLND
@@ -2320,43 +2240,64 @@ PHP_FUNCTION(mysqli_refresh)
}
/* }}} */
-/* {{{ proto int mysqli_stmt_attr_set(object stmt, int attr, int mode)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_stmt_attr_set)
{
MY_STMT *stmt;
zval *mysql_stmt;
zend_long mode_in;
-#if MYSQL_VERSION_ID >= 50107
- my_bool mode_b;
-#endif
+ my_bool mode_b;
unsigned long mode;
zend_long attr;
void *mode_p;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oll", &mysql_stmt, mysqli_stmt_class_entry, &attr, &mode_in) == FAILURE) {
- return;
+ RETURN_THROWS();
}
- MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
- if (mode_in < 0) {
- php_error_docref(NULL, E_WARNING, "mode should be non-negative, " ZEND_LONG_FMT " passed", mode_in);
- RETURN_FALSE;
- }
+ MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
switch (attr) {
-#if MYSQL_VERSION_ID >= 50107
case STMT_ATTR_UPDATE_MAX_LENGTH:
+ if (mode_in != 0 && mode_in != 1) {
+ zend_argument_value_error(ERROR_ARG_POS(3), "must be 0 or 1 for attribute MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH");
+ RETURN_THROWS();
+ }
mode_b = (my_bool) mode_in;
mode_p = &mode_b;
break;
-#endif
- default:
+ case STMT_ATTR_CURSOR_TYPE:
+ switch (mode_in) {
+ case CURSOR_TYPE_NO_CURSOR:
+ case CURSOR_TYPE_READ_ONLY:
+ case CURSOR_TYPE_FOR_UPDATE:
+ case CURSOR_TYPE_SCROLLABLE:
+ break;
+ default:
+ zend_argument_value_error(ERROR_ARG_POS(3), "must be one of the MYSQLI_CURSOR_TYPE_* constants "
+ "for attribute MYSQLI_STMT_ATTR_CURSOR_TYPE");
+ RETURN_THROWS();
+ }
mode = mode_in;
mode_p = &mode;
break;
+ case STMT_ATTR_PREFETCH_ROWS:
+ if (mode_in < 1) {
+ zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than 0 for attribute MYSQLI_STMT_ATTR_PREFETCH_ROWS");
+ RETURN_THROWS();
+ }
+ mode = mode_in;
+ mode_p = &mode;
+ break;
+ default:
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be one of "
+ "MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, "
+ "MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE");
+ RETURN_THROWS();
}
-#if !defined(MYSQLI_USE_MYSQLND)
+
+// TODO Can unify this?
+#ifndef MYSQLI_USE_MYSQLND
if (mysql_stmt_attr_set(stmt->stmt, attr, mode_p)) {
#else
if (FAIL == mysql_stmt_attr_set(stmt->stmt, attr, mode_p)) {
@@ -2368,8 +2309,7 @@ PHP_FUNCTION(mysqli_stmt_attr_set)
}
/* }}} */
-/* {{{ proto int mysqli_stmt_attr_get(object stmt, int attr)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_stmt_attr_get)
{
MY_STMT *stmt;
@@ -2379,31 +2319,35 @@ PHP_FUNCTION(mysqli_stmt_attr_get)
int rc;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_stmt, mysqli_stmt_class_entry, &attr) == FAILURE) {
- return;
+ RETURN_THROWS();
}
+
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
if ((rc = mysql_stmt_attr_get(stmt->stmt, attr, &value))) {
- RETURN_FALSE;
- }
+ /* Success corresponds to 0 return value and a non-zero value
+ * should only happen if the attr/option is unknown */
+ zend_argument_value_error(ERROR_ARG_POS(2), "must be one of "
+ "MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, "
+ "MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE");
+ RETURN_THROWS();
+ }
+
-#if MYSQL_VERSION_ID >= 50107
if (attr == STMT_ATTR_UPDATE_MAX_LENGTH)
value = *((my_bool *)&value);
-#endif
RETURN_LONG((unsigned long)value);
}
/* }}} */
-/* {{{ proto int mysqli_stmt_errno(object stmt)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_stmt_errno)
{
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_INITIALIZED);
@@ -2411,8 +2355,7 @@ PHP_FUNCTION(mysqli_stmt_errno)
}
/* }}} */
-/* {{{ proto string mysqli_stmt_error(object stmt)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_stmt_error)
{
MY_STMT *stmt;
@@ -2420,7 +2363,7 @@ PHP_FUNCTION(mysqli_stmt_error)
const char * err;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_INITIALIZED);
@@ -2431,9 +2374,7 @@ PHP_FUNCTION(mysqli_stmt_error)
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_init(object link)
- Initialize statement object
-*/
+/* {{{ Initialize statement object */
PHP_FUNCTION(mysqli_stmt_init)
{
MY_MYSQL *mysql;
@@ -2442,7 +2383,7 @@ PHP_FUNCTION(mysqli_stmt_init)
MYSQLI_RESOURCE *mysqli_resource;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O",&mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -2463,9 +2404,7 @@ PHP_FUNCTION(mysqli_stmt_init)
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_prepare(object stmt, string query)
- prepare server side statement with query
-*/
+/* {{{ prepare server side statement with query */
PHP_FUNCTION(mysqli_stmt_prepare)
{
MY_STMT *stmt;
@@ -2474,7 +2413,7 @@ PHP_FUNCTION(mysqli_stmt_prepare)
size_t query_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry, &query, &query_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_INITIALIZED);
@@ -2488,8 +2427,7 @@ PHP_FUNCTION(mysqli_stmt_prepare)
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_result_metadata(object stmt)
- return result set from statement */
+/* {{{ return result set from statement */
PHP_FUNCTION(mysqli_stmt_result_metadata)
{
MY_STMT *stmt;
@@ -2498,7 +2436,7 @@ PHP_FUNCTION(mysqli_stmt_result_metadata)
MYSQLI_RESOURCE *mysqli_resource;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2514,19 +2452,18 @@ PHP_FUNCTION(mysqli_stmt_result_metadata)
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_store_result(object stmt)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_stmt_store_result)
{
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
-#if !defined(MYSQLI_USE_MYSQLND)
+#ifndef MYSQLI_USE_MYSQLND
{
/*
If the user wants to store the data and we have BLOBs/TEXTs we try to allocate
@@ -2543,11 +2480,7 @@ PHP_FUNCTION(mysqli_stmt_store_result)
stmt->stmt->fields[i].type == MYSQL_TYPE_LONG_BLOB ||
stmt->stmt->fields[i].type == MYSQL_TYPE_GEOMETRY))
{
-#if MYSQL_VERSION_ID >= 50107
- my_bool tmp=1;
-#else
- uint32_t tmp=1;
-#endif
+ my_bool tmp = 1;
mysql_stmt_attr_set(stmt->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &tmp);
break;
}
@@ -2563,8 +2496,7 @@ PHP_FUNCTION(mysqli_stmt_store_result)
}
/* }}} */
-/* {{{ proto string mysqli_stmt_sqlstate(object stmt)
-*/
+/* {{{ */
PHP_FUNCTION(mysqli_stmt_sqlstate)
{
MY_STMT *stmt;
@@ -2572,7 +2504,7 @@ PHP_FUNCTION(mysqli_stmt_sqlstate)
const char * state;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2583,8 +2515,7 @@ PHP_FUNCTION(mysqli_stmt_sqlstate)
}
/* }}} */
-/* {{{ proto object mysqli_store_result(object link [, int flags])
- Buffer result set on client */
+/* {{{ Buffer result set on client */
PHP_FUNCTION(mysqli_store_result)
{
MY_MYSQL *mysql;
@@ -2595,10 +2526,10 @@ PHP_FUNCTION(mysqli_store_result)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_link, mysqli_link_class_entry, &flags) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-#if MYSQLI_USE_MYSQLND
+#ifdef 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);
@@ -2618,15 +2549,14 @@ PHP_FUNCTION(mysqli_store_result)
}
/* }}} */
-/* {{{ proto int mysqli_thread_id(object link)
- Return the current thread ID */
+/* {{{ Return the current thread ID */
PHP_FUNCTION(mysqli_thread_id)
{
MY_MYSQL *mysql;
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -2634,16 +2564,18 @@ PHP_FUNCTION(mysqli_thread_id)
}
/* }}} */
-/* {{{ proto bool mysqli_thread_safe(void)
- Return whether thread safety is given or not */
+/* {{{ Return whether thread safety is given or not */
PHP_FUNCTION(mysqli_thread_safe)
{
+ if (zend_parse_parameters_none() == FAILURE) {
+ RETURN_THROWS();
+ }
+
RETURN_BOOL(mysql_thread_safe());
}
/* }}} */
-/* {{{ proto mixed mysqli_use_result(object link)
- Directly retrieve query results - do not buffer results on client side */
+/* {{{ Directly retrieve query results - do not buffer results on client side */
PHP_FUNCTION(mysqli_use_result)
{
MY_MYSQL *mysql;
@@ -2652,7 +2584,7 @@ PHP_FUNCTION(mysqli_use_result)
MYSQLI_RESOURCE *mysqli_resource;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -2671,15 +2603,14 @@ PHP_FUNCTION(mysqli_use_result)
}
/* }}} */
-/* {{{ proto int mysqli_warning_count(object link)
- Return number of warnings from the last query for the given link */
+/* {{{ Return number of warnings from the last query for the given link */
PHP_FUNCTION(mysqli_warning_count)
{
MY_MYSQL *mysql;
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
- return;
+ RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);