}
/* }}} */
-/* {{{ proto bool mysqli_bind_param(object stmt, string types, mixed variable [,mixed,....])
+/* {{{ proto bool mysqli_stmt_bind_param(object stmt, string types, mixed variable [,mixed,....])
Bind variables to a prepared statement as parameters */
-PHP_FUNCTION(mysqli_bind_param)
+PHP_FUNCTION(mysqli_stmt_bind_param)
{
zval ***args;
int argc = ZEND_NUM_ARGS();
}
ofs++;
}
-
+#ifndef HAVE_MYSQLI_OLDAPI
+ rc = mysql_stmt_bind_param(stmt->stmt, bind);
+#else
rc = mysql_bind_param(stmt->stmt, bind);
+#endif
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
if (rc) {
}
/* }}} */
-/* {{{ proto bool mysqli_bind_result(object stmt, mixed var, [,mixed, ...])
+/* {{{ proto bool mysqli_stmt_bind_result(object stmt, mixed var, [,mixed, ...])
Bind variables to a prepared statement for result storage */
/* TODO:
do_alloca, free_alloca
*/
-PHP_FUNCTION(mysqli_bind_result)
+PHP_FUNCTION(mysqli_stmt_bind_result)
{
zval ***args;
int argc = ZEND_NUM_ARGS();
if (var_cnt != stmt->stmt->field_count) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of bind variables doesn't match number of fields in prepared statmement.");
+ efree(args);
RETURN_FALSE;
}
case MYSQL_TYPE_FLOAT:
convert_to_double_ex(args[i]);
stmt->result.buf[ofs].type = IS_DOUBLE;
- stmt->result.buf[ofs].buflen = 0;
+ stmt->result.buf[ofs].buflen = sizeof(double);
+
+ /* allocate buffer for double */
+ stmt->result.buf[ofs].val = (char *)emalloc(sizeof(double));
bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
- bind[ofs].buffer = (gptr)&Z_DVAL_PP(args[i]);
+ bind[ofs].buffer = stmt->result.buf[ofs].val;
bind[ofs].is_null = &stmt->result.is_null[ofs];
break;
convert_to_long_ex(args[i]);
stmt->result.buf[ofs].type = IS_LONG;
stmt->result.buf[ofs].buflen = 0;
+ stmt->result.buf[ofs].val = (char *)emalloc(sizeof(long));
bind[ofs].buffer_type = MYSQL_TYPE_LONG;
- bind[ofs].buffer = (gptr)&Z_LVAL_PP(args[i]);
+ bind[ofs].buffer = stmt->result.buf[ofs].val;
bind[ofs].is_null = &stmt->result.is_null[ofs];
break;
case MYSQL_TYPE_LONGLONG:
stmt->result.buf[ofs].type = IS_STRING;
stmt->result.buf[ofs].buflen = sizeof(my_ulonglong);
- stmt->result.buf[ofs].buffer = (char *)emalloc(stmt->result.buf[ofs].buflen);
+ stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
bind[ofs].buffer_type = MYSQL_TYPE_LONGLONG;
- bind[ofs].buffer = stmt->result.buf[ofs].buffer;
+ bind[ofs].buffer = stmt->result.buf[ofs].val;
bind[ofs].is_null = &stmt->result.is_null[ofs];
bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
break;
stmt->result.buf[ofs].type = IS_STRING;
stmt->result.buf[ofs].buflen =
(stmt->stmt->fields) ? (stmt->stmt->fields[ofs].length) ? stmt->stmt->fields[ofs].length + 1: 256: 256;
- stmt->result.buf[ofs].buffer = (char *)emalloc(stmt->result.buf[ofs].buflen);
+ stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
bind[ofs].buffer_type = MYSQL_TYPE_STRING;
- bind[ofs].buffer = stmt->result.buf[ofs].buffer;
+ bind[ofs].buffer = stmt->result.buf[ofs].val;
bind[ofs].is_null = &stmt->result.is_null[ofs];
bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
bind[ofs].length = &stmt->result.buf[ofs].buflen;
}
}
+#ifndef HAVE_MYSQLI_OLDAPI
+ rc = mysql_stmt_bind_result(stmt->stmt, bind);
+#else
rc = mysql_bind_result(stmt->stmt, bind);
+#endif
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
if (rc) {
}
/* }}} */
-/* {{{ proto bool mysqli_execute(object stmt)
+/* {{{ proto bool mysqli_stmt_execute(object stmt)
Execute a prepared statement */
-PHP_FUNCTION(mysqli_execute)
+PHP_FUNCTION(mysqli_stmt_execute)
{
STMT *stmt;
zval *mysql_stmt;
}
}
}
-
+#ifndef HAVE_MYSQLI_OLDAPI
+ if (mysql_stmt_execute(stmt->stmt)) {
+#else
if (mysql_execute(stmt->stmt)) {
+#endif
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
RETURN_FALSE;
}
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch(object stmt)
+/* {{{ proto mixed mysqli_stmt_fetch(object stmt)
Fetch results from a prepared statement into the bound variables */
-PHP_FUNCTION(mysqli_fetch)
+PHP_FUNCTION(mysqli_stmt_fetch)
{
STMT *stmt;
zval *mysql_stmt;
unsigned int i;
ulong ret;
+ long lval;
+ double dval;
+ my_ulonglong llval;
+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
return;
for (i = 0; i < stmt->result.var_cnt; i++) {
if (stmt->result.buf[i].type == IS_STRING) {
- memset(stmt->result.buf[i].buffer, 0, stmt->result.buf[i].buflen);
+ memset(stmt->result.buf[i].val, 0, stmt->result.buf[i].buflen);
}
}
-
+#ifndef HAVE_MYSQLI_OLDAPI
+ if (!(ret = mysql_stmt_fetch(stmt->stmt))) {
+#else
if (!(ret = mysql_fetch(stmt->stmt))) {
-
+#endif
for (i = 0; i < stmt->result.var_cnt; i++) {
+ if (stmt->result.vars[i]->type == IS_STRING && stmt->result.vars[i]->value.str.len) {
+ efree(stmt->result.vars[i]->value.str.val);
+ }
if (!stmt->result.is_null[i]) {
switch (stmt->result.buf[i].type) {
case IS_LONG:
- stmt->result.vars[i]->type = IS_LONG;
+ memcpy(&lval, stmt->result.buf[i].val, sizeof(long));
+ ZVAL_LONG(stmt->result.vars[i], lval);
break;
case IS_DOUBLE:
- stmt->result.vars[i]->type = IS_DOUBLE;
+ memcpy(&dval, stmt->result.buf[i].val, sizeof(double));
+ ZVAL_DOUBLE(stmt->result.vars[i], dval);
break;
case IS_STRING:
if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_LONGLONG) {
char tmp[50];
- my_ulonglong lval;
- memcpy (&lval, stmt->result.buf[i].buffer, sizeof(my_ulonglong));
- if (lval != (long)lval) {
+ memcpy (&llval, stmt->result.buf[i].val, sizeof(my_ulonglong));
+ if (llval != (long)llval) {
/* even though lval is declared as unsigned, the value
* may be negative. Therefor we cannot use %llu and must
* use %lld.
*/
- sprintf((char *)&tmp, "%lld", lval);
+ sprintf((char *)&tmp, "%lld", llval);
ZVAL_STRING(stmt->result.vars[i], tmp, 1);
} else {
- ZVAL_LONG(stmt->result.vars[i], lval);
+ ZVAL_LONG(stmt->result.vars[i], llval);
}
} else {
- if (stmt->result.vars[i]->type == IS_STRING) {
- efree(stmt->result.vars[i]->value.str.val);
- }
- ZVAL_STRING(stmt->result.vars[i], stmt->result.buf[i].buffer, 1);
+ ZVAL_STRING(stmt->result.vars[i], stmt->result.buf[i].val, 1);
}
break;
default:
/* {{{ proto int mysqli_param_count(object stmt) {
Return the number of parameter for the given statement */
-PHP_FUNCTION(mysqli_param_count)
+PHP_FUNCTION(mysqli_stmt_param_count)
{
STMT *stmt;
zval *mysql_stmt;
}
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
+#ifndef HAVE_MYSQLI_OLDAPI
+ RETURN_LONG(mysql_stmt_param_count(stmt->stmt));
+#else
RETURN_LONG(mysql_param_count(stmt->stmt));
+#endif
}
/* }}} */
stmt = (STMT *)ecalloc(1,sizeof(STMT));
+#ifdef HAVE_MYSQLI_OLDAPI
stmt->stmt = mysql_prepare(mysql, query, query_len);
-
+#else
+ if ((stmt->stmt = mysql_stmt_init(mysql))) {
+ if (mysql_stmt_prepare(stmt->stmt, query, query_len)) {
+ mysql_stmt_close(stmt->stmt);
+ stmt->stmt = NULL;
+ }
+ }
+#endif
if (!stmt->stmt) {
MYSQLI_REPORT_MYSQL_ERROR(mysql);
efree(stmt);
}
/* }}} */
-/* {{{ proto mixed mysqli_get_metadata(object stmt)
- return result set from statement */
-PHP_FUNCTION(mysqli_get_metadata)
-{
- STMT *stmt;
- MYSQL_RES *result;
- zval *mysql_stmt;
- MYSQLI_RESOURCE *mysqli_resource;
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
- return;
- }
- MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
-
- if (!(result = mysql_get_metadata(stmt->stmt))){
- MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
- RETURN_FALSE;
- }
-
- mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
- mysqli_resource->ptr = (void *)result;
- MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
-}
-/* }}} */
-
/* {{{ 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 */
PHP_FUNCTION(mysqli_real_connect)
/* {{{ proto bool mysqli_send_long_data(object stmt, int param_nr, string data)
*/
-PHP_FUNCTION(mysqli_send_long_data)
+PHP_FUNCTION(mysqli_stmt_send_long_data)
{
STMT *stmt;
zval *mysql_stmt;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter number");
RETURN_FALSE;
}
-
+#ifndef HAVE_MYSQLI_OLDAPI
+ if (mysql_stmt_send_long_data(stmt->stmt, param_nr, data, data_len)) {
+#else
if (mysql_send_long_data(stmt->stmt, param_nr, data, data_len)) {
+#endif
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
+#ifndef HAVE_MYSQLI_OLDAPI
+/* {{{ proto object mysqli_stmt_init(object link)
+ Initialize statement object
+*/
+PHP_FUNCTION(mysqli_stmt_init)
+{
+ MYSQL *mysql;
+ STMT *stmt;
+ zval *mysql_link;
+ MYSQLI_RESOURCE *mysqli_resource;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",&mysql_link, mysqli_link_class_entry) == FAILURE) {
+ return;
+ }
+ MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
+
+ if (!(stmt->stmt = mysql_stmt_init(mysql))) {
+ RETURN_FALSE;
+ }
+
+ mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
+ mysqli_resource->ptr = (void *)stmt;
+ MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_stmt_class_entry);
+}
+/* }}} */
+
+/* {{{ proto bool mysqli_stmt_prepare(object link, string query)
+ prepare server side statement with query
+*/
+PHP_FUNCTION(mysqli_stmt_prepare)
+{
+ STMT *stmt;
+ zval *mysql_stmt;
+ char *query;
+ int query_len;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry, &query, &query_len) == FAILURE) {
+ return;
+ }
+ MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
+
+ if (mysql_stmt_prepare(stmt->stmt, query, query_len)) {
+ MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+}
+/* }}} */
+#endif
+
+/* {{{ proto mixed mysqli_stmt_result_metadata(object stmt)
+ return result set from statement */
+PHP_FUNCTION(mysqli_stmt_result_metadata)
+{
+ STMT *stmt;
+ MYSQL_RES *result;
+ zval *mysql_stmt;
+ MYSQLI_RESOURCE *mysqli_resource;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
+ return;
+ }
+ MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
+
+#ifndef HAVE_MYSQLI_OLDAPI
+ if (!(result = mysql_stmt_result_metadata(stmt->stmt))){
+#else
+ if (!(result = mysql_get_metadata(stmt->stmt))){
+#endif
+ MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
+ RETURN_FALSE;
+ }
+
+ mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
+ mysqli_resource->ptr = (void *)result;
+ MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
+}
+/* }}} */
+
/* {{{ proto bool mysqli_stmt_store_result(stmt)
*/
PHP_FUNCTION(mysqli_stmt_store_result)
function_entry mysqli_functions[] = {
PHP_FE(mysqli_affected_rows, NULL)
PHP_FE(mysqli_autocommit, NULL)
- PHP_FE(mysqli_bind_param, third_arg_force_by_ref_rest)
- PHP_FE(mysqli_bind_result, second_arg_force_by_ref_rest)
PHP_FE(mysqli_change_user, NULL)
PHP_FE(mysqli_character_set_name, NULL)
- PHP_FALIAS(mysqli_client_encoding,
- mysqli_character_set_name, NULL)
PHP_FE(mysqli_close, NULL)
PHP_FE(mysqli_commit, NULL)
PHP_FE(mysqli_connect, NULL)
PHP_FE(mysqli_enable_rpl_parse, NULL)
PHP_FE(mysqli_errno, NULL)
PHP_FE(mysqli_error, NULL)
- PHP_FE(mysqli_execute, NULL)
- PHP_FE(mysqli_fetch, NULL)
+ PHP_FE(mysqli_stmt_execute, NULL)
+ PHP_FALIAS(mysqli_execute, mysqli_stmt_execute, NULL)
PHP_FE(mysqli_fetch_field, NULL)
PHP_FE(mysqli_fetch_fields, NULL)
PHP_FE(mysqli_fetch_field_direct, NULL)
PHP_FE(mysqli_get_client_info, NULL)
PHP_FE(mysqli_get_client_version, NULL)
PHP_FE(mysqli_get_host_info, NULL)
- PHP_FE(mysqli_get_metadata, NULL)
PHP_FE(mysqli_get_proto_info, NULL)
PHP_FE(mysqli_get_server_info, NULL)
PHP_FE(mysqli_get_server_version, NULL)
PHP_FE(mysqli_num_fields, NULL)
PHP_FE(mysqli_num_rows, NULL)
PHP_FE(mysqli_options, NULL)
- PHP_FE(mysqli_param_count, NULL)
PHP_FE(mysqli_ping, NULL)
PHP_FE(mysqli_prepare, NULL)
PHP_FE(mysqli_report, NULL)
PHP_FE(mysqli_query, NULL)
PHP_FE(mysqli_real_connect, NULL)
PHP_FE(mysqli_real_escape_string, NULL)
- PHP_FALIAS(mysqli_escape_string,
- mysqli_real_escape_string, NULL)
PHP_FE(mysqli_real_query, NULL)
PHP_FE(mysqli_rollback, NULL)
PHP_FE(mysqli_rpl_parse_enabled, NULL)
PHP_FE(mysqli_rpl_probe, NULL)
PHP_FE(mysqli_rpl_query_type, NULL)
PHP_FE(mysqli_select_db, NULL)
- PHP_FE(mysqli_send_long_data, NULL)
+#ifndef HAVE_MYSQLI_OLDAPI
+ PHP_FE(mysqli_stmt_init, NULL)
+ PHP_FE(mysqli_stmt_prepare, NULL)
+#endif
+ PHP_FE(mysqli_stmt_result_metadata, NULL)
+ PHP_FE(mysqli_stmt_send_long_data, NULL)
+ PHP_FE(mysqli_stmt_bind_param, third_arg_force_by_ref_rest)
+ PHP_FE(mysqli_stmt_bind_result, second_arg_force_by_ref_rest)
+ PHP_FE(mysqli_stmt_fetch, NULL)
+ PHP_FE(mysqli_stmt_param_count, NULL)
PHP_FE(mysqli_send_query, NULL)
#ifdef HAVE_EMBEDDED_MYSQLI
PHP_FE(mysqli_server_end, NULL)
PHP_FE(mysqli_server_init, NULL)
#endif
- PHP_FALIAS(mysqli_set_opt, mysqli_options, NULL)
PHP_FE(mysqli_slave_query, NULL)
#if MYSQL_VERSION_ID >= 40101
PHP_FE(mysqli_sqlstate, NULL)
PHP_FE(mysqli_thread_safe, NULL)
PHP_FE(mysqli_use_result, NULL)
PHP_FE(mysqli_warning_count, NULL)
+
+ /* Aliases */
+ PHP_FALIAS(mysqli_bind_param,
+ mysqli_stmt_bind_param, third_arg_force_by_ref_rest)
+ PHP_FALIAS(mysqli_bind_result,
+ mysqli_stmt_bind_result, second_arg_force_by_ref_rest)
+ PHP_FALIAS(mysqli_client_encoding,
+ mysqli_character_set_name, NULL)
+ PHP_FALIAS(mysqli_escape_string,
+ mysqli_real_escape_string, NULL)
+ PHP_FALIAS(mysqli_fetch, mysqli_stmt_fetch, NULL)
+ PHP_FALIAS(mysqli_param_count,
+ mysqli_stmt_param_count, NULL)
+ PHP_FALIAS(mysqli_get_metadata,
+ mysqli_stmt_result_metadata, NULL)
+ PHP_FALIAS(mysqli_send_long_data,
+ mysqli_stmt_send_long_data, NULL)
+ PHP_FALIAS(mysqli_set_opt, mysqli_options, NULL)
+
{NULL, NULL, NULL} /* Must be the last line in mysqli_functions[] */
};
/* }}} */
PHP_FALIAS(slave_query,mysqli_slave_query,NULL)
PHP_FALIAS(ssl_set,mysqli_ssl_set,NULL)
PHP_FALIAS(stat,mysqli_stat,NULL)
+#ifndef HAVE_MYSQLI_OLDAPI
+ PHP_FALIAS(stmt_init,mysqli_stmt_init, NULL)
+#endif
PHP_FALIAS(store_result,mysqli_store_result,NULL)
PHP_FALIAS(thread_safe,mysqli_thread_safe,NULL)
PHP_FALIAS(use_result,mysqli_use_result,NULL)
*/
function_entry mysqli_stmt_methods[] = {
PHP_FALIAS(affected_rows,mysqli_stmt_affected_rows,NULL)
- PHP_FALIAS(bind_param,mysqli_bind_param,second_arg_force_by_ref_rest)
- PHP_FALIAS(bind_result,mysqli_bind_result,all_args_force_by_ref)
+ PHP_FALIAS(bind_param,mysqli_stmt_bind_param,second_arg_force_by_ref_rest)
+ PHP_FALIAS(bind_result,mysqli_stmt_bind_result,all_args_force_by_ref)
PHP_FALIAS(close,mysqli_stmt_close,NULL)
PHP_FALIAS(data_seek,mysqli_stmt_data_seek,NULL)
- PHP_FALIAS(execute,mysqli_execute,NULL)
- PHP_FALIAS(fetch,mysqli_fetch,NULL)
- PHP_FALIAS(get_metadata, mysqli_get_metadata,NULL)
+ PHP_FALIAS(execute,mysqli_stmt_execute,NULL)
+ PHP_FALIAS(fetch,mysqli_stmt_fetch,NULL)
+ PHP_FALIAS(get_metadata, mysqli_stmt_result_metadata,NULL)
PHP_FALIAS(num_rows, mysqli_stmt_num_rows,NULL)
- PHP_FALIAS(send_long_data,mysqli_send_long_data,NULL)
+ PHP_FALIAS(send_long_data,mysqli_stmt_send_long_data,NULL)
PHP_FALIAS(stmt,mysqli_prepare,NULL)
+#ifndef HAVE_MYSQLI_OLDAPI
+ PHP_FALIAS(prepare,mysqli_stmt_prepare, NULL)
+#endif
PHP_FALIAS(store_result,mysqli_stmt_store_result,NULL)
{NULL, NULL, NULL}
};