ret = FAILURE;
obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
- if (member->type != IS_STRING) {
+ if (member->type != IS_STRING && member->type != IS_UNICODE) {
tmp_member = *member;
zval_copy_ctor(&tmp_member);
- convert_to_string(&tmp_member);
+ convert_to_text(&tmp_member);
member = &tmp_member;
}
if (obj->prop_handler != NULL) {
- ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
+ ret = zend_u_hash_find(obj->prop_handler, UG(unicode)?IS_UNICODE:IS_STRING, Z_UNIVAL_P(member), Z_UNILEN_P(member)+1, (void **) &hnd);
}
if (ret == SUCCESS) {
- if (strcmp(obj->zo.ce->name.s, "mysqli_driver") &&
- (!obj->ptr || ((MYSQLI_RESOURCE *)(obj->ptr))->status < MYSQLI_STATUS_INITIALIZED)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", obj->zo.ce->name );
+ int is_driver;
+
+ if (UG(unicode)) {
+ UChar *ustr = USTR_MAKE("mysqli_driver");
+ is_driver = u_strcmp(obj->zo.ce->name.u, ustr);
+ USTR_FREE(ustr);
+ } else {
+ is_driver = strcmp(obj->zo.ce->name.s, "mysqli_driver");
+ }
+
+ if (is_driver && (!obj->ptr || ((MYSQLI_RESOURCE *)(obj->ptr))->status < MYSQLI_STATUS_INITIALIZED)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %R", UG(unicode)?IS_UNICODE:IS_STRING, obj->zo.ce->name );
retval = EG(uninitialized_zval_ptr);
return(retval);
}
obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
if (obj->prop_handler != NULL) {
- ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
+ ret = zend_u_hash_find((HashTable *)obj->prop_handler, Z_TYPE_P(member), Z_UNIVAL_P(member), Z_UNILEN_P(member)+1, (void **) &hnd);
}
if (ret == SUCCESS) {
hnd->write_func(obj, value TSRMLS_CC);
mysqli_base_class = mysqli_base_class->parent;
}
- zend_hash_find(&classes, mysqli_base_class->name.s, mysqli_base_class->name_length + 1,
+ zend_u_hash_find(&classes, UG(unicode)?IS_UNICODE:IS_STRING, mysqli_base_class->name, mysqli_base_class->name_length + 1,
(void **) &intern->prop_handler);
zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
mysqli_object_handlers.get_property_ptr_ptr = std_hnd->get_property_ptr_ptr;
mysqli_object_handlers.get_constructor = php_mysqli_constructor_get;
- zend_hash_init(&classes, 0, NULL, NULL, 1);
+ zend_u_hash_init(&classes, 0, NULL, NULL, 1, 1);
INIT_CLASS_ENTRY(cex, "mysqli_sql_exception", mysqli_exception_methods);
#ifdef HAVE_SPL
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, mysqli_driver_methods);
ce = mysqli_driver_class_entry;
- zend_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1);
+ zend_u_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
zend_hash_add(&classes, ce->name.s, ce->name_length+1, &mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, mysqli_link_methods);
ce = mysqli_link_class_entry;
- zend_hash_init(&mysqli_link_properties, 0, NULL, NULL, 1);
+ zend_u_hash_init(&mysqli_link_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_link_properties, mysqli_link_property_entries);
zend_hash_add(&classes, ce->name.s, ce->name_length+1, &mysqli_link_properties, sizeof(mysqli_link_properties), NULL);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, mysqli_warning_methods);
ce = mysqli_warning_class_entry;
ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
- zend_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1);
+ zend_u_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
zend_hash_add(&classes, ce->name.s, ce->name_length+1, &mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_result", mysqli_result_class_entry, mysqli_result_methods);
ce = mysqli_result_class_entry;
- zend_hash_init(&mysqli_result_properties, 0, NULL, NULL, 1);
+ zend_u_hash_init(&mysqli_result_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_result_properties, mysqli_result_property_entries);
zend_hash_add(&classes, ce->name.s, ce->name_length+1, &mysqli_result_properties, sizeof(mysqli_result_properties), NULL);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_stmt", mysqli_stmt_class_entry, mysqli_stmt_methods);
ce = mysqli_stmt_class_entry;
- zend_hash_init(&mysqli_stmt_properties, 0, NULL, NULL, 1);
+ zend_u_hash_init(&mysqli_stmt_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_stmt_properties, mysqli_stmt_property_entries);
zend_hash_add(&classes, ce->name.s, ce->name_length+1, &mysqli_stmt_properties, sizeof(mysqli_stmt_properties), NULL);
-
+
+
/* mysqli_options */
REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_GROUP", MYSQL_READ_DEFAULT_GROUP, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_FILE", MYSQL_READ_DEFAULT_FILE, CONST_CS | CONST_PERSISTENT);
}
/* }}} */
-/* {{{ mixed mysqli_stmt_construct()
+/* {{{ mixed mysqli_stmt_construct() U
constructor for statement object.
Parameters:
object -> mysqli_stmt_init
zval *mysql_link;
MY_STMT *stmt;
MYSQLI_RESOURCE *mysqli_resource;
- char *statement;
- int stmt_len;
+ MYSQLI_STRING statement;
switch (ZEND_NUM_ARGS())
{
stmt->stmt = mysql_stmt_init(mysql->mysql);
break;
case 2:
- if (zend_parse_parameters(2 TSRMLS_CC, "Os", &mysql_link, mysqli_link_class_entry, &statement, &stmt_len)==FAILURE) {
+ if (zend_parse_parameters(2 TSRMLS_CC, "OT", &mysql_link, mysqli_link_class_entry, MYSQLI_GET_STRING(statement))==FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
+
+ MYSQLI_CONVERT_PARAM_STRING(statement, MYSQLI_CONV_UTF8);
if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) {
- mysql_stmt_prepare(stmt->stmt, statement, stmt_len);
+ mysql_stmt_prepare(stmt->stmt, (char *)statement.buf, statement.buflen);
}
+ MYSQLI_FREE_STRING(statement);
break;
default:
WRONG_PARAM_COUNT;
}
/* }}} */
-/* {{{ mixed mysqli_result_construct()
+/* {{{ mixed mysqli_result_construct() U
constructor for result object.
Parameters:
object [, mode] -> mysqli_store/use_result
unsigned long *field_len;
zval *ctor_params = NULL;
zend_class_entry *ce = NULL;
+ void *classname;
+ int classname_len;
+ zend_uchar classname_type;
if (into_object) {
- char *class_name;
- int class_name_len;
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sz", &mysql_result, mysqli_result_class_entry, &class_name, &class_name_len, &ctor_params) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|Tz", &mysql_result, mysqli_result_class_entry,
+ &classname, &classname_len, &classname_type, &ctor_params) == FAILURE) {
return;
}
if (ZEND_NUM_ARGS() < (getThis() ? 1 : 2)) {
ce = zend_standard_class_def;
} else {
- ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
+ ce = zend_u_fetch_class(classname_type, ZSTR(classname), classname_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
}
if (!ce) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%R'", classname_type, ZSTR(classname));
return;
}
fetchtype = MYSQLI_ASSOC;
MAKE_STD_ZVAL(res);
- ZVAL_STRINGL(res, row[i], field_len[i], 1);
+ if (UG(unicode)) {
+ UChar *ustr;
+ int ulen;
+
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, row[i], field_len[i]);
+ ZVAL_UNICODEL(res, ustr, ulen, 0);
+ } else {
+ ZVAL_STRINGL(res, row[i], field_len[i], 1);
+ }
if (fetchtype & MYSQLI_NUM) {
add_index_zval(return_value, i, res);
if (fetchtype & MYSQLI_NUM) {
ZVAL_ADDREF(res);
}
- add_assoc_zval(return_value, fields[i].name, res);
+ if (UG(unicode)) {
+ UChar *ustr;
+ int ulen;
+
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, fields[i].name, strlen(fields[i].name));
+ /* maybe a bug in add_u_assoc_zval_ex: string is truncated when specifying ulen only */
+ add_u_assoc_zval_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen + 1, res);
+ efree(ustr);
+ } else {
+ add_assoc_zval(return_value, fields[i].name, res);
+ }
}
} else {
if (fetchtype & MYSQLI_NUM) {
#include "ext/standard/info.h"
#include "php_mysqli.h"
-/* {{{ proto mixed mysqli_affected_rows(object link)
+/* {{{ proto mixed mysqli_affected_rows(object link) U
Get number of affected rows in previous MySQL operation */
PHP_FUNCTION(mysqli_affected_rows)
{
}
/* }}} */
-/* {{{ proto bool mysqli_autocommit(object link, bool mode)
+/* {{{ proto bool mysqli_autocommit(object link, bool mode) U
Turn auto commit on or of */
PHP_FUNCTION(mysqli_autocommit)
{
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_bind_param(object stmt, string types, mixed variable [,mixed,....])
+/* {{{ proto bool mysqli_stmt_bind_param(object stmt, string types, mixed variable [,mixed,....]) U
Bind variables to a prepared statement as parameters */
PHP_FUNCTION(mysqli_stmt_bind_param)
{
MY_STMT *stmt;
zval *mysql_stmt;
MYSQL_BIND *bind;
- char *types;
- int typelen;
+ MYSQLI_STRING types;
unsigned long rc;
/* calculate and check number of parameters */
WRONG_PARAM_COUNT;
}
- if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry, &types, &typelen) == FAILURE) {
+ if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry, MYSQLI_GET_STRING(types)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
+ MYSQLI_CONVERT_PARAM_STRING(types, MYSQLI_CONV_ASCII);
num_vars = argc - 1;
if (getThis()) {
--num_vars;
}
- if (typelen != argc - start) {
+ if (types.buflen != argc - start) {
/* number of bind variables doesn't match number of elements in type definition string */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements in type definition string doesn't match number of bind variables");
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end_2;
}
- if (typelen != stmt->stmt->param_count) {
+ if (types.buflen != stmt->stmt->param_count) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of variables doesn't match number of parameters in prepared statement");
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end_2;
}
/* prevent leak if variables are already bound */
if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
efree(args);
- WRONG_PARAM_COUNT;
+ zend_wrong_param_count(TSRMLS_C);
+ goto end_2;
}
stmt->param.is_null = ecalloc(num_vars, sizeof(char));
for (i=start; i < argc; i++) {
/* set specified type */
- switch (types[ofs]) {
+ switch (((char *)types.buf)[ofs]) {
case 'd': /* Double */
bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
bind[ofs].buffer = (gptr)&Z_DVAL_PP(args[i]);
break;
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i+1);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", ((char *)types.buf)[ofs], i+1);
RETVAL_FALSE;
- goto end;
+ goto end_1;
}
ofs++;
}
if (rc) {
RETVAL_FALSE;
- goto end;
+ goto end_1;
}
stmt->param.var_cnt = num_vars;
}
}
RETVAL_TRUE;
-end:
+end_1:
efree(args);
efree(bind);
+end_2:
+ MYSQLI_FREE_STRING(types);
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_bind_result(object stmt, mixed var, [,mixed, ...])
+/* {{{ proto bool mysqli_stmt_bind_result(object stmt, mixed var, [,mixed, ...]) U
Bind variables to a prepared statement for result storage */
/* TODO:
}
/* }}} */
-/* {{{ proto bool mysqli_change_user(object link, string user, string password, string database)
+/* {{{ proto bool mysqli_change_user(object link, string user, string password, string database) U
Change logged-in user of the active connection */
PHP_FUNCTION(mysqli_change_user)
{
- MY_MYSQL *mysql;
- zval *mysql_link = NULL;
- char *user, *password, *dbname;
- int user_len, password_len, dbname_len;
+ MY_MYSQL *mysql;
+ zval *mysql_link = NULL;
+ MYSQLI_STRING user, password, dbname;
ulong rc;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osss", &mysql_link, mysqli_link_class_entry, &user, &user_len, &password, &password_len, &dbname, &dbname_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osss", &mysql_link, mysqli_link_class_entry,
+ MYSQLI_GET_STRING(user), MYSQLI_GET_STRING(password), MYSQLI_GET_STRING(dbname)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
- rc = mysql_change_user(mysql->mysql, user, password, dbname);
+ MYSQLI_CONVERT_PARAM_STRING(user, MYSQLI_CONV_UTF8);
+ MYSQLI_CONVERT_PARAM_STRING(password, MYSQLI_CONV_UTF8);
+ MYSQLI_CONVERT_PARAM_STRING(dbname, MYSQLI_CONV_UTF8);
+
+ rc = mysql_change_user(mysql->mysql, user.buf, password.buf, dbname.buf);
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
+ MYSQLI_FREE_STRING(user);
+ MYSQLI_FREE_STRING(password);
+ MYSQLI_FREE_STRING(dbname);
+
if (rc) {
RETURN_FALSE;
}
}
/* }}} */
-/* {{{ proto string mysqli_character_set_name(object link)
+/* {{{ proto string mysqli_character_set_name(object link) U
Returns the name of the character set used for this connection */
PHP_FUNCTION(mysqli_character_set_name)
{
MY_MYSQL *mysql;
zval *mysql_link;
+ char *csname;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
return;
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
- RETURN_STRING((char *) mysql_character_set_name(mysql->mysql), 1);
+ csname = (char *)mysql_character_set_name(mysql->mysql);
+
+ MYSQLI_RETURN_CONV_STRINGL(MYSQLI_CONV_UTF8, csname, strlen(csname), 1);
}
/* }}} */
-/* {{{ proto bool mysqli_close(object link)
+/* {{{ proto bool mysqli_close(object link) U
Close connection */
PHP_FUNCTION(mysqli_close)
{
}
/* }}} */
-/* {{{ proto bool mysqli_commit(object link)
+/* {{{ proto bool mysqli_commit(object link) U
Commit outstanding actions and close transaction */
PHP_FUNCTION(mysqli_commit)
{
}
/* }}} */
-/* {{{ proto bool mysqli_data_seek(object result, int offset)
+/* {{{ proto bool mysqli_data_seek(object result, int offset) U
Move internal result pointer */
PHP_FUNCTION(mysqli_data_seek)
{
}
/* }}} */
-/* {{{ proto void mysqli_debug(string debug)
+/* {{{ proto void mysqli_debug(string debug) U
*/
PHP_FUNCTION(mysqli_debug)
{
- char *debug;
- int debug_len;
+ MYSQLI_STRING debug;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &debug, &debug_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", MYSQLI_GET_STRING(debug)) == FAILURE) {
return;
}
- mysql_debug(debug);
+ MYSQLI_CONVERT_PARAM_STRING(debug, MYSQLI_CONV_ASCII);
+
+ mysql_debug((char *)debug.buf);
+ MYSQLI_FREE_STRING(debug);
RETURN_TRUE;
}
/* }}} */
-/* {{{ proto bool mysqli_dump_debug_info(object link)
+/* {{{ proto bool mysqli_dump_debug_info(object link) U
*/
PHP_FUNCTION(mysqli_dump_debug_info)
{
}
/* }}} */
-/* {{{ proto int mysqli_errno(object link)
+/* {{{ proto int mysqli_errno(object link) U
Returns the numerical value of the error message from previous MySQL operation */
PHP_FUNCTION(mysqli_errno)
{
}
/* }}} */
-/* {{{ proto string mysqli_error(object link)
+/* {{{ proto string mysqli_error(object link) U
Returns the text of the error message from previous MySQL operation */
PHP_FUNCTION(mysqli_error)
{
MY_MYSQL *mysql;
zval *mysql_link;
+ char *strerr;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
- RETURN_STRING((char *)mysql_error(mysql->mysql),1);
+
+ strerr = (char *)mysql_error(mysql->mysql);
+ MYSQLI_RETURN_CONV_STRINGL(MYSQLI_CONV_UTF8, strerr, strlen(strerr), 1);
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_execute(object stmt)
+/* {{{ proto bool mysqli_stmt_execute(object stmt) U
Execute a prepared statement */
PHP_FUNCTION(mysqli_stmt_execute)
{
if ( !(stmt->param.is_null[i] = (stmt->param.vars[i]->type == IS_NULL)) ) {
switch (stmt->stmt->params[i].buffer_type) {
case MYSQL_TYPE_VAR_STRING:
- convert_to_string_ex(&stmt->param.vars[i]);
- stmt->stmt->params[i].buffer = Z_STRVAL_PP(&stmt->param.vars[i]);
- stmt->stmt->params[i].buffer_length = Z_STRLEN_PP(&stmt->param.vars[i]);
+ if (UG(unicode) && Z_TYPE_P(stmt->param.vars[i]) == IS_UNICODE) {
+ zend_unicode_to_string(MYSQLI_CONV_UTF8, &stmt->stmt->params[i].buffer, (int *)&stmt->stmt->params[i].buffer_length,
+ Z_USTRVAL_PP(&stmt->param.vars[i]), Z_USTRLEN_PP(&stmt->param.vars[i]));
+ } else {
+ if (Z_TYPE_P(stmt->param.vars[i]) != IS_STRING) {
+ convert_to_string_ex(&stmt->param.vars[i]);
+ }
+ stmt->stmt->params[i].buffer = Z_STRVAL_PP(&stmt->param.vars[i]);
+ stmt->stmt->params[i].buffer_length = Z_STRLEN_PP(&stmt->param.vars[i]);
+ }
break;
case MYSQL_TYPE_DOUBLE:
convert_to_double_ex(&stmt->param.vars[i]);
}
if (mysql_stmt_execute(stmt->stmt)) {
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
- RETURN_FALSE;
+ RETVAL_FALSE;
+ } else {
+ RETVAL_TRUE;
}
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
php_mysqli_report_index(stmt->query, stmt->stmt->mysql->server_status TSRMLS_CC);
}
-
- RETURN_TRUE;
+
+ /* free converted utf8 strings */
+ if (UG(unicode)) {
+ for (i = 0; i < stmt->param.var_cnt; i++) {
+ if (stmt->stmt->params[i].buffer_type == MYSQL_TYPE_VAR_STRING) {
+ efree(stmt->stmt->params[i].buffer);
+ }
+ }
+ }
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_fetch(object stmt)
+/* {{{ proto mixed mysqli_stmt_fetch(object stmt) U
Fetch results from a prepared statement into the bound variables */
PHP_FUNCTION(mysqli_stmt_fetch)
{
if (Z_TYPE_P(stmt->result.vars[i]) == IS_STRING) {
efree(stmt->result.vars[i]->value.str.val);
}
+ if (Z_TYPE_P(stmt->result.vars[i]) == IS_UNICODE) {
+ USTR_FREE(stmt->result.vars[i]->value.ustr.val);
+ }
if (!stmt->result.is_null[i]) {
switch (stmt->result.buf[i].type) {
case IS_LONG:
} while (--j > 0);
tmp[10]= '\0';
/* unsigned int > INT_MAX is 10 digis - ALWAYS */
- ZVAL_STRINGL(stmt->result.vars[i], tmp, 10, 0);
+ if (UG(unicode)) {
+ UChar *ubuf = NULL;
+ int ulen;
+ zend_string_to_unicode(MYSQLI_CONV_ASCII, &ubuf, &ulen, tmp, strlen(tmp));
+ ZVAL_UNICODEL(stmt->result.vars[i], ubuf, ulen, 0);
+ efree(tmp);
+ } else {
+ ZVAL_STRINGL(stmt->result.vars[i], tmp, 10, 0);
+ }
break;
}
}
if (uns && llval > 9223372036854775807L) {
#elif SIZEOF_LONG==4
if ((uns && llval > L64(2147483647)) ||
- (!uns && (( L64(2147483647) < (my_longlong) llval) || (L64(-2147483648) > (my_longlong) llval))))
+ (!uns && (( L64(2147483647) < (my_longlong) llval) ||
+ (L64(-2147483648) > (my_longlong) llval))))
{
#endif
char tmp[22];
* use MYSQLI_LL_SPEC.
*/
sprintf((char *)&tmp, (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC, llval);
- ZVAL_STRING(stmt->result.vars[i], tmp, 1);
+ if (UG(unicode)) {
+ UChar *ubuf = NULL;
+ int ulen;
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ubuf, &ulen, tmp, strlen(tmp));
+ ZVAL_UNICODEL(stmt->result.vars[i], ubuf, ulen, 0);
+ } else {
+ ZVAL_STRING(stmt->result.vars[i], tmp, 1);
+ }
} else {
ZVAL_LONG(stmt->result.vars[i], llval);
}
- }
+ }
#if MYSQL_VERSION_ID > 50002
else if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT) {
llval = *(my_ulonglong *)stmt->result.buf[i].val;
}
#endif
else {
- ZVAL_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val, stmt->result.buf[i].buflen, 1);
- }
+ if (UG(unicode)) {
+ UChar *ubuf = NULL;
+ int ulen;
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ubuf, &ulen, stmt->result.buf[i].val,
+ stmt->result.buf[i].buflen);
+ ZVAL_UNICODEL(stmt->result.vars[i], ubuf, ulen, 0);
+ } else {
+ ZVAL_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val, stmt->result.buf[i].buflen, 1);
+ }
+
+ }
break;
default:
break;
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_field (object result)
+
+void php_add_field_properties(zval *value, MYSQL_FIELD *field)
+{
+ if (UG(unicode)) {
+ UChar *ustr;
+ int ulen;
+
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (field->name) ? field->name : "",
+ (field->name) ? strlen(field->name) : 0);
+ add_property_unicodel(value, "name", ustr, ulen, 0);
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (field->org_name) ? field->org_name : "",
+ (field->org_name) ? strlen(field->org_name) : 0);
+ add_property_unicodel(value, "orgname", ustr, ulen, 0);
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (field->table) ? field->table : "",
+ (field->table) ? strlen(field->table) : 0);
+ add_property_unicodel(value, "table", ustr, ulen, 0);
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (field->org_table) ? field->org_table : "",
+ (field->org_table) ? strlen(field->org_table) : 0);
+ add_property_unicodel(value, "orgtable", ustr, ulen, 0);
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (field->def) ? field->def : "",
+ (field->def) ? strlen(field->def) : 0);
+ add_property_unicodel(value, "def", ustr, ulen, 0);
+ } else {
+ add_property_string(value, "name",(field->name ? field->name : ""), 1);
+ add_property_string(value, "orgname",(field->org_name ? field->org_name : ""), 1);
+ add_property_string(value, "table",(field->table ? field->table : ""), 1);
+ add_property_string(value, "orgtable",(field->org_table ? field->org_table : ""), 1);
+ add_property_string(value, "def",(field->def ? field->def : ""), 1);
+ }
+ add_property_long(value, "max_length", field->max_length);
+ add_property_long(value, "length", field->length);
+ add_property_long(value, "charsetnr", field->charsetnr);
+ add_property_long(value, "flags", field->flags);
+ add_property_long(value, "type", field->type);
+ add_property_long(value, "decimals", field->decimals);
+}
+
+/* {{{ proto mixed mysqli_fetch_field (object result) U
Get column information from a result and return as an object */
PHP_FUNCTION(mysqli_fetch_field)
{
}
object_init(return_value);
-
- add_property_string(return_value, "name",(field->name ? field->name : ""), 1);
- add_property_string(return_value, "orgname",(field->org_name ? field->org_name : ""), 1);
- add_property_string(return_value, "table",(field->table ? field->table : ""), 1);
- add_property_string(return_value, "orgtable",(field->org_table ? field->org_table : ""), 1);
- add_property_string(return_value, "def",(field->def ? field->def : ""), 1);
- add_property_long(return_value, "max_length", field->max_length);
- add_property_long(return_value, "length", field->length);
- add_property_long(return_value, "charsetnr", field->charsetnr);
- add_property_long(return_value, "flags", field->flags);
- add_property_long(return_value, "type", field->type);
- add_property_long(return_value, "decimals", field->decimals);
+ php_add_field_properties(return_value, field);
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_fields (object result)
+/* {{{ proto mixed mysqli_fetch_fields (object result) U
Return array of objects containing field meta-data */
PHP_FUNCTION(mysqli_fetch_fields)
{
for (i = 0; i < mysql_num_fields(result); i++) {
field = mysql_fetch_field_direct(result, i);
-
MAKE_STD_ZVAL(obj);
object_init(obj);
- add_property_string(obj, "name",(field->name ? field->name : ""), 1);
- add_property_string(obj, "orgname",(field->org_name ? field->org_name : ""), 1);
- add_property_string(obj, "table",(field->table ? field->table : ""), 1);
- add_property_string(obj, "orgtable",(field->org_table ? field->org_table : ""), 1);
- add_property_string(obj, "def",(field->def ? field->def : ""), 1);
- add_property_long(obj, "max_length", field->max_length);
- add_property_long(obj, "length", field->length);
- add_property_long(obj, "charsetnr", field->charsetnr);
- add_property_long(obj, "flags", field->flags);
- add_property_long(obj, "type", field->type);
- add_property_long(obj, "decimals", field->decimals);
-
+ php_add_field_properties(obj, field);
add_index_zval(return_value, i, obj);
}
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_field_direct (object result, int offset)
+/* {{{ proto mixed mysqli_fetch_field_direct (object result, int offset) U
Fetch meta-data for a single field */
PHP_FUNCTION(mysqli_fetch_field_direct)
{
}
object_init(return_value);
-
- add_property_string(return_value, "name",(field->name ? field->name : ""), 1);
- add_property_string(return_value, "orgname",(field->org_name ? field->org_name : ""), 1);
- add_property_string(return_value, "table",(field->table ? field->table : ""), 1);
- add_property_string(return_value, "orgtable",(field->org_table ? field->org_table : ""), 1);
- add_property_string(return_value, "def",(field->def ? field->def : ""), 1);
- add_property_long(return_value, "max_length", field->max_length);
- add_property_long(return_value, "length", field->length);
- add_property_long(return_value, "charsetnr", field->charsetnr);
- add_property_long(return_value, "flags", field->flags);
- add_property_long(return_value, "type", field->type);
- add_property_long(return_value, "decimals", field->decimals);
+ php_add_field_properties(return_value, field);
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_lengths (object result)
+/* {{{ proto mixed mysqli_fetch_lengths (object result) U
Get the length of each output in a result */
PHP_FUNCTION(mysqli_fetch_lengths)
{
}
/* }}} */
-/* {{{ proto array mysqli_fetch_row (object result)
+/* {{{ proto array mysqli_fetch_row (object result) U
Get a result row as an enumerated array */
PHP_FUNCTION(mysqli_fetch_row)
{
}
/* }}} */
-/* {{{ proto int mysqli_field_count(object link)
+/* {{{ proto int mysqli_field_count(object link) U
Fetch the number of fields returned by the last query for the given link
*/
PHP_FUNCTION(mysqli_field_count)
}
/* }}} */
-/* {{{ proto int mysqli_field_seek(object result, int fieldnr)
+/* {{{ proto int mysqli_field_seek(object result, int fieldnr) U
Set result pointer to a specified field offset
*/
PHP_FUNCTION(mysqli_field_seek)
}
/* }}} */
-/* {{{ proto int mysqli_field_tell(object result)
+/* {{{ proto int mysqli_field_tell(object result) U
Get current field offset of result pointer */
PHP_FUNCTION(mysqli_field_tell)
{
}
/* }}} */
-/* {{{ proto void mysqli_free_result(object result)
+/* {{{ proto void mysqli_free_result(object result) U
Free query result memory for the given result handle */
PHP_FUNCTION(mysqli_free_result)
{
}
/* }}} */
-/* {{{ proto string mysqli_get_client_info(void)
+/* {{{ proto string mysqli_get_client_info(void) U
Get MySQL client info */
PHP_FUNCTION(mysqli_get_client_info)
{
}
/* }}} */
-/* {{{ proto int mysqli_get_client_version(void)
+/* {{{ proto int mysqli_get_client_version(void) U
Get MySQL client info */
PHP_FUNCTION(mysqli_get_client_version)
{
}
/* }}} */
-/* {{{ proto string mysqli_get_host_info (object link)
+/* {{{ proto string mysqli_get_host_info (object link) U
Get MySQL host info */
-PHP_FUNCTION(mysqli_get_host_info)
+PHP_FUNCTION(mysqli_get_host_info)
{
MY_MYSQL *mysql;
zval *mysql_link = NULL;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
- RETURN_STRING((mysql->mysql->host_info) ? mysql->mysql->host_info : "", 1);
+ MYSQLI_RETURN_CONV_STRING(MYSQLI_CONV_ASCII, mysql->mysql->host_info);
}
/* }}} */
-/* {{{ proto int mysqli_get_proto_info(object link)
+/* {{{ proto int mysqli_get_proto_info(object link) U
Get MySQL protocol information */
PHP_FUNCTION(mysqli_get_proto_info)
{
}
/* }}} */
-/* {{{ proto string mysqli_get_server_info(object link)
+/* {{{ proto string mysqli_get_server_info(object link) U
Get MySQL server info */
PHP_FUNCTION(mysqli_get_server_info)
{
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
- RETURN_STRING((char *)mysql_get_server_info(mysql->mysql), 1);
+ MYSQLI_RETURN_CONV_STRING(MYSQLI_CONV_ASCII, (char *)mysql_get_server_info(mysql->mysql));
}
/* }}} */
-/* {{{ proto int mysqli_get_server_version(object link)
+/* {{{ proto int mysqli_get_server_version(object link) U
Return the MySQL version for the server referenced by the given link */
PHP_FUNCTION(mysqli_get_server_version)
{
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
- RETURN_STRING((mysql->mysql->info) ? mysql->mysql->info : "", 1);
+ MYSQLI_RETURN_CONV_STRING(MYSQLI_CONV_ASCII, mysql->mysql->info);
}
/* }}} */
-/* {{{ proto resource mysqli_init(void)
+/* {{{ proto resource mysqli_init(void) U
Initialize mysqli and return a resource for use with mysql_real_connect */
PHP_FUNCTION(mysqli_init)
{
}
/* }}} */
-/* {{{ proto mixed mysqli_insert_id(object link)
+/* {{{ proto mixed mysqli_insert_id(object link) U
Get the ID generated from the previous INSERT operation */
PHP_FUNCTION(mysqli_insert_id)
{
}
/* }}} */
-/* {{{ proto bool mysqli_kill(object link, int processid)
+/* {{{ proto bool mysqli_kill(object link, int processid) U
Kill a mysql process on the server */
PHP_FUNCTION(mysqli_kill)
{
}
/* }}} */
-/* {{{ proto void mysqli_set_local_infile_default(object link)
+/* {{{ proto void mysqli_set_local_infile_default(object link) U
unsets user defined handler for load local infile command */
PHP_FUNCTION(mysqli_set_local_infile_default)
{
}
/* }}} */
-/* {{{ proto bool mysqli_set_local_infile_handler(object link, callback read_func)
+/* {{{ proto bool mysqli_set_local_infile_handler(object link, callback read_func) U
Set callback functions for LOAD DATA LOCAL INFILE */
PHP_FUNCTION(mysqli_set_local_infile_handler)
{
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
+ if (UG(unicode)) {
+ convert_to_string(callback_func);
+ }
+
/* check callback function */
if (!zend_is_callable(callback_func, 0, &callback_name)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a valid callback function %R", Z_TYPE(callback_name), Z_UNIVAL(callback_name));
}
/* }}} */
-/* {{{ proto bool mysqli_more_results(object link)
+/* {{{ proto bool mysqli_more_results(object link) U
check if there any more query results from a multi query */
PHP_FUNCTION(mysqli_more_results)
{
}
/* }}} */
-/* {{{ proto bool mysqli_next_result(object link)
+/* {{{ proto bool mysqli_next_result(object link) U
read next result from multi_query */
PHP_FUNCTION(mysqli_next_result) {
MY_MYSQL *mysql;
}
/* }}} */
-/* {{{ proto int mysqli_num_fields(object result)
+/* {{{ proto int mysqli_num_fields(object result) U
Get number of fields in result */
PHP_FUNCTION(mysqli_num_fields)
{
}
/* }}} */
-/* {{{ proto mixed mysqli_num_rows(object result)
+/* {{{ proto mixed mysqli_num_rows(object result) U
Get number of rows in result */
PHP_FUNCTION(mysqli_num_rows)
{
}
/* }}} */
-/* {{{ proto bool mysqli_options(object link, int flags, mixed values)
+/* {{{ proto bool mysqli_options(object link, int flags, mixed values) U
Set options */
PHP_FUNCTION(mysqli_options)
{
case IS_STRING:
ret = mysql_options(mysql->mysql, mysql_option, Z_STRVAL_PP(&mysql_value));
break;
+ case IS_UNICODE:
+ {
+ MYSQLI_STRING optstr;
+
+ optstr.buf = Z_USTRVAL_P(mysql_value);
+ optstr.buflen = Z_USTRLEN_P(mysql_value);
+ optstr.buftype = IS_UNICODE;
+ MYSQLI_CONVERT_PARAM_STRING(optstr, MYSQLI_CONV_UTF8);
+ ret = mysql_options(mysql->mysql, mysql_option, (char *)optstr.buf);
+ MYSQLI_FREE_STRING(optstr);
+ break;
+ }
default:
convert_to_long_ex(&mysql_value);
l_value = Z_LVAL_PP(&mysql_value);
}
/* }}} */
-
-/* {{{ proto bool mysqli_ping(object link)
+/* {{{ proto bool mysqli_ping(object link) U
Ping a server connection or reconnect if there is no connection */
PHP_FUNCTION(mysqli_ping)
{
}
/* }}} */
-/* {{{ proto mixed mysqli_prepare(object link, string query)
+/* {{{ proto mixed mysqli_prepare(object link, string query) U
Prepare a SQL statement for execution */
PHP_FUNCTION(mysqli_prepare)
{
MY_MYSQL *mysql;
MY_STMT *stmt;
- char *query = NULL;
- unsigned int query_len;
+ MYSQLI_STRING query;
zval *mysql_link;
MYSQLI_RESOURCE *mysqli_resource;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",&mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OT",&mysql_link, mysqli_link_class_entry, MYSQLI_GET_STRING(query)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) {
- if (mysql_stmt_prepare(stmt->stmt, query, query_len)) {
+ MYSQLI_CONVERT_PARAM_STRING(query, MYSQLI_CONV_UTF8);
+ if (mysql_stmt_prepare(stmt->stmt, query.buf, query.buflen)) {
char last_error[MYSQL_ERRMSG_SIZE];
char sqlstate[SQLSTATE_LENGTH+1];
unsigned int last_errno;
memcpy(mysql->mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH+1);
}
}
- /* don't joing to the previous if because it won't work if mysql_stmt_prepare_fails */
+
+ /* don't initialize stmt->query with NULL, we ecalloc()-ed the memory */
+ /* Get performance boost if reporting is switched off */
+ if (stmt->stmt && query.buflen && (MyG(report_mode) & MYSQLI_REPORT_INDEX)) {
+ stmt->query = (char *)emalloc(query.buflen + 1);
+ memcpy(stmt->query, query.buf, query.buflen);
+ stmt->query[query.buflen] = '\0';
+ }
+
+ MYSQLI_FREE_STRING(query);
+
+ /* don't join to the previous if because it won't work if mysql_stmt_prepare_fails */
if (!stmt->stmt) {
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
efree(stmt);
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = (void *)stmt;
- /* don't initialize stmt->query with NULL, we ecalloc()-ed the memory */
- /* Get performance boost if reporting is switched off */
- if (query_len && (MyG(report_mode) & MYSQLI_REPORT_INDEX)) {
- stmt->query = (char *)emalloc(query_len + 1);
- memcpy(stmt->query, query, query_len);
- stmt->query[query_len] = '\0';
- }
/* change status */
mysqli_resource->status = MYSQLI_STATUS_VALID;
}
/* }}} */
-/* {{{ proto bool mysqli_real_connect(object link [,string hostname [,string username [,string passwd [,string dbname [,int port [,string socket [,int flags]]]]]]])
+/* {{{ proto bool mysqli_real_connect(object link [,string hostname [,string username [,string passwd [,string dbname [,int port [,string socket [,int flags]]]]]]]) U
Open a connection to a mysql server */
PHP_FUNCTION(mysqli_real_connect)
{
MY_MYSQL *mysql;
- char *hostname = NULL, *username=NULL, *passwd=NULL, *dbname=NULL, *socket=NULL;
- unsigned int hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
+ MYSQLI_STRING hostname, username, passwd, dbname, socket;
unsigned long port=0, flags=0;
zval *mysql_link;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sssslsl", &mysql_link, mysqli_link_class_entry,
- &hostname, &hostname_len, &username, &username_len, &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len,
+ /* optional MYSQLI_STRING parameters have to be initialized */
+ memset(&hostname, 0, sizeof(MYSQLI_STRING));
+ memset(&username, 0, sizeof(MYSQLI_STRING));
+ memset(&dbname, 0, sizeof(MYSQLI_STRING));
+ memset(&passwd, 0, sizeof(MYSQLI_STRING));
+ memset(&socket, 0, sizeof(MYSQLI_STRING));
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|TTTTlTl", &mysql_link, mysqli_link_class_entry,
+ MYSQLI_GET_STRING(hostname), MYSQLI_GET_STRING(username), MYSQLI_GET_STRING(passwd), MYSQLI_GET_STRING(dbname), &port, MYSQLI_GET_STRING(socket),
&flags) == FAILURE) {
return;
}
- if (!socket_len) {
- socket = NULL;
- }
+ MYSQLI_CONVERT_PARAM_STRING(hostname, MYSQLI_CONV_ASCII);
+ MYSQLI_CONVERT_PARAM_STRING(username, MYSQLI_CONV_UTF8);
+ MYSQLI_CONVERT_PARAM_STRING(passwd, MYSQLI_CONV_UTF8);
+ MYSQLI_CONVERT_PARAM_STRING(dbname, MYSQLI_CONV_UTF8);
+ MYSQLI_CONVERT_PARAM_STRING(socket, MYSQLI_CONV_ASCII);
- /* TODO: safe mode handling */
- if (PG(sql_safe_mode)) {
- } else {
- if (!passwd) {
- passwd = MyG(default_pw);
- if (!username){
- username = MyG(default_user);
- if (!hostname) {
- hostname = MyG(default_host);
- }
- }
- }
- }
+ /* TODO: default values */
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_INITIALIZED);
flags ^= CLIENT_LOCAL_FILES;
}
- if (!socket) {
- socket = MyG(default_socket);
- }
-
- if (mysql_real_connect(mysql->mysql,hostname,username,passwd,dbname,port,socket,flags) == NULL) {
+ if (mysql_real_connect(mysql->mysql, hostname.buf, username.buf, passwd.buf, dbname.buf ,port,(socket.buflen) ? socket.buf : NULL,flags) == NULL) {
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
php_mysqli_throw_sql_exception( mysql->mysql->net.sqlstate, mysql->mysql->net.last_errno TSRMLS_CC,
"%s", mysql->mysql->net.last_error);
/* change status */
MYSQLI_SET_STATUS(&mysql_link, MYSQLI_STATUS_INITIALIZED);
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end;
}
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *)mysql_error(mysql->mysql) TSRMLS_CC);
/* change status */
MYSQLI_SET_STATUS(&mysql_link, MYSQLI_STATUS_VALID);
- RETURN_TRUE;
+ RETVAL_TRUE;
+end:
+ MYSQLI_FREE_STRING(hostname);
+ MYSQLI_FREE_STRING(username);
+ MYSQLI_FREE_STRING(passwd);
+ MYSQLI_FREE_STRING(dbname);
+ MYSQLI_FREE_STRING(socket);
}
/* }}} */
-/* {{{ proto bool mysqli_real_query(object link, string query)
+/* {{{ proto bool mysqli_real_query(object link, string query) U
Binary-safe version of mysql_query() */
PHP_FUNCTION(mysqli_real_query)
{
MY_MYSQL *mysql;
zval *mysql_link;
- char *query = NULL;
- unsigned int query_len;
+ MYSQLI_STRING query;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, MYSQLI_GET_STRING(query)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
+ MYSQLI_CONVERT_PARAM_STRING(query, MYSQLI_CONV_UTF8);
MYSQLI_DISABLE_MQ; /* disable multi statements/queries */
- if (mysql_real_query(mysql->mysql, query, query_len)) {
+ if (mysql_real_query(mysql->mysql, query.buf, query.buflen)) {
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
- RETURN_FALSE;
- }
-
- if (!mysql_field_count(mysql->mysql)) {
- if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
- php_mysqli_report_index(query, mysql->mysql->server_status TSRMLS_CC);
+ RETVAL_FALSE;
+ } else {
+ if (!mysql_field_count(mysql->mysql)) {
+ if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
+ php_mysqli_report_index(query.buf, mysql->mysql->server_status TSRMLS_CC);
+ }
}
+ RETVAL_TRUE;
}
-
- RETURN_TRUE;
+ MYSQLI_FREE_STRING(query);
}
/* }}} */
-/* {{{ proto string mysqli_real_escape_string(object link, string escapestr)
+/* {{{ proto string mysqli_real_escape_string(object link, string escapestr) U
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;
- char *escapestr, *newstr;
- int escapestr_len, newstr_len;
+ MY_MYSQL *mysql;
+ zval *mysql_link = NULL;
+ MYSQLI_STRING escapestr;
+ char *newstr;
+ int newstr_len;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &escapestr, &escapestr_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, MYSQLI_GET_STRING(escapestr)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
+ MYSQLI_CONVERT_PARAM_STRING(escapestr, MYSQLI_CONV_UTF8);
- newstr = safe_emalloc(2, escapestr_len, 1);
- newstr_len = mysql_real_escape_string(mysql->mysql, newstr, escapestr, escapestr_len);
+ newstr = safe_emalloc(2, escapestr.buflen, 1);
+ newstr_len = mysql_real_escape_string(mysql->mysql, newstr, escapestr.buf, escapestr.buflen);
newstr = erealloc(newstr, newstr_len + 1);
-
- RETURN_STRINGL(newstr, newstr_len, 0);
+
+ MYSQLI_FREE_STRING(escapestr);
+ MYSQLI_RETURN_CONV_STRINGL(MYSQLI_CONV_UTF8, newstr, newstr_len, 0);
}
/* }}} */
-/* {{{ proto bool mysqli_rollback(object link)
+/* {{{ proto bool mysqli_rollback(object link) U
Undo actions from current transaction */
PHP_FUNCTION(mysqli_rollback)
{
}
/* }}} */
-/* {{{ proto bool mysqli_send_long_data(object stmt, int param_nr, string data)
+/* {{{ proto bool mysqli_send_long_data(object stmt, int param_nr, string data) U
*/
PHP_FUNCTION(mysqli_stmt_send_long_data)
{
MY_STMT *stmt;
zval *mysql_stmt;
- char *data;
long param_nr;
- int data_len;
+ MYSQLI_STRING data;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols", &mysql_stmt, mysqli_stmt_class_entry, ¶m_nr, &data, &data_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols", &mysql_stmt, mysqli_stmt_class_entry, ¶m_nr, MYSQLI_GET_STRING(data)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
+ MYSQLI_CONVERT_PARAM_STRING(data, MYSQLI_CONV_UTF8);
if (param_nr < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter number");
- RETURN_FALSE;
- }
- if (mysql_stmt_send_long_data(stmt->stmt, param_nr, data, data_len)) {
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end;
+ }
+ if (mysql_stmt_send_long_data(stmt->stmt, param_nr, data.buf, data.buflen)) {
+ RETVAL_FALSE;
+ } else {
+ RETVAL_TRUE;
}
- RETURN_TRUE;
+end:
+ MYSQLI_FREE_STRING(data);
}
/* }}} */
-
-/* {{{ proto mixed mysqli_stmt_affected_rows(object stmt)
+/* {{{ proto mixed mysqli_stmt_affected_rows(object stmt) U
Return the number of rows affected in the last query for the given link */
PHP_FUNCTION(mysqli_stmt_affected_rows)
{
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_close(object stmt)
+/* {{{ proto bool mysqli_stmt_close(object stmt) U
Close statement */
PHP_FUNCTION(mysqli_stmt_close)
{
}
/* }}} */
-/* {{{ proto void mysqli_stmt_data_seek(object stmt, int offset)
+/* {{{ proto void mysqli_stmt_data_seek(object stmt, int offset) U
Move internal result pointer */
PHP_FUNCTION(mysqli_stmt_data_seek)
{
}
/* }}} */
-/* {{{ proto int mysqli_stmt_field_count(object stmt) {
+/* {{{ proto int mysqli_stmt_field_count(object stmt) { U
Return the number of result columns for the given statement */
PHP_FUNCTION(mysqli_stmt_field_count)
{
}
/* }}} */
-/* {{{ proto void mysqli_stmt_free_result(object stmt)
+/* {{{ proto void mysqli_stmt_free_result(object stmt) U
Free stored result memory for the given statement handle */
PHP_FUNCTION(mysqli_stmt_free_result)
{
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_insert_id(object stmt)
+/* {{{ proto mixed mysqli_stmt_insert_id(object stmt) U
Get the ID generated from the previous INSERT operation */
PHP_FUNCTION(mysqli_stmt_insert_id)
{
}
/* }}} */
-/* {{{ proto int mysqli_stmt_param_count(object stmt) {
+/* {{{ proto int mysqli_stmt_param_count(object stmt) U
Return the number of parameter for the given statement */
PHP_FUNCTION(mysqli_stmt_param_count)
{
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_reset(object stmt)
+/* {{{ proto bool mysqli_stmt_reset(object stmt) U
reset a prepared statement */
PHP_FUNCTION(mysqli_stmt_reset)
{
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_num_rows(object stmt)
+/* {{{ proto mixed mysqli_stmt_num_rows(object stmt) U
Return the number of rows in statements result set */
PHP_FUNCTION(mysqli_stmt_num_rows)
{
}
/* }}} */
-/* {{{ proto string mysqli_select_db(object link, string dbname)
+/* {{{ proto string mysqli_select_db(object link, string dbname) U
Select a MySQL database */
PHP_FUNCTION(mysqli_select_db)
{
- MY_MYSQL *mysql;
- zval *mysql_link;
- char *dbname;
- int dbname_len;
+ MY_MYSQL *mysql;
+ zval *mysql_link;
+ MYSQLI_STRING dbname;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &dbname, &dbname_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, MYSQLI_GET_STRING(dbname)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
+ MYSQLI_CONVERT_PARAM_STRING(dbname, MYSQLI_CONV_UTF8);
- if (!mysql_select_db(mysql->mysql, dbname)) {
- RETURN_TRUE;
+ if (!mysql_select_db(mysql->mysql, (char *)dbname.buf)) {
+ RETVAL_TRUE;
+ } else {
+ MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
+ RETURN_FALSE;
}
-
- MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
- RETURN_FALSE;
+ MYSQLI_FREE_STRING(dbname);
}
/* }}} */
-/* {{{ proto string mysqli_sqlstate(object link)
+/* {{{ proto string mysqli_sqlstate(object link) U
Returns the SQLSTATE error from previous MySQL operation */
PHP_FUNCTION(mysqli_sqlstate)
{
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
- RETURN_STRING((char *)mysql_sqlstate(mysql->mysql),1);
+ MYSQLI_RETURN_CONV_STRING(MYSQLI_CONV_ASCII, (char *)mysql_sqlstate(mysql->mysql));
}
/* }}} */
-/* {{{ proto bool mysqli_ssl_set(object link ,string key ,string cert ,string ca ,string capath ,string cipher])
+/* {{{ proto bool mysqli_ssl_set(object link ,string key ,string cert ,string ca ,string capath ,string cipher]) U
*/
PHP_FUNCTION(mysqli_ssl_set)
{
- MY_MYSQL *mysql;
- zval *mysql_link;
- char *ssl_parm[5];
- int ssl_parm_len[5], i;
+ MY_MYSQL *mysql;
+ zval *mysql_link;
+ MYSQLI_STRING ssl_parm[5];
+ int i;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 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) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osssss", &mysql_link, mysqli_link_class_entry,
+ MYSQLI_GET_STRING(ssl_parm[0]), MYSQLI_GET_STRING(ssl_parm[1]), MYSQLI_GET_STRING(ssl_parm[2]),
+ MYSQLI_GET_STRING(ssl_parm[3]), MYSQLI_GET_STRING(ssl_parm[4])) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
for (i=0; i < 5; i++) {
- if (!ssl_parm_len[i]) {
- ssl_parm[i] = NULL;
+ MYSQLI_CONVERT_PARAM_STRING(ssl_parm[0], MYSQLI_CONV_ASCII);
+ if (!ssl_parm[i].buflen) {
+ ssl_parm[i].buf = NULL;
}
}
- mysql_ssl_set(mysql->mysql, ssl_parm[0], ssl_parm[1], ssl_parm[2], ssl_parm[3], ssl_parm[4]);
+ mysql_ssl_set(mysql->mysql, ssl_parm[0].buf, ssl_parm[1].buf, ssl_parm[2].buf, ssl_parm[3].buf, ssl_parm[4].buf);
+
+ for (i=0; i < 5; i++) {
+ MYSQLI_FREE_STRING(ssl_parm[i]);
+ }
RETURN_TRUE;
}
/* }}} */
-/* {{{ proto mixed mysqli_stat(object link)
+/* {{{ proto mixed mysqli_stat(object link) U
Get current system status */
PHP_FUNCTION(mysqli_stat)
{
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
if ((stat = (char *)mysql_stat(mysql->mysql))) {
- RETURN_STRING(stat, 1);
+ MYSQLI_RETURN_CONV_STRING(MYSQLI_CONV_ASCII, stat);
}
RETURN_FALSE;
}
/* }}} */
-/* {{{ proto int mysqli_stmt_attr_set(object stmt, long attr, long mode)
+/* {{{ proto int mysqli_stmt_attr_set(object stmt, long attr, long mode) U
*/
PHP_FUNCTION(mysqli_stmt_attr_set)
{
}
/* }}} */
-/* {{{ proto int mysqli_stmt_attr_get(object stmt, long attr)
+/* {{{ proto int mysqli_stmt_attr_get(object stmt, long attr) U
*/
PHP_FUNCTION(mysqli_stmt_attr_get)
{
}
/* }}} */
-/* {{{ proto int mysqli_stmt_errno(object stmt)
+/* {{{ proto int mysqli_stmt_errno(object stmt) U
*/
PHP_FUNCTION(mysqli_stmt_errno)
{
}
/* }}} */
-/* {{{ proto string mysqli_stmt_error(object stmt)
+/* {{{ proto string mysqli_stmt_error(object stmt) U
*/
PHP_FUNCTION(mysqli_stmt_error)
{
}
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_INITIALIZED);
- RETURN_STRING((char *)mysql_stmt_error(stmt->stmt),1);
+ MYSQLI_RETURN_CONV_STRING(MYSQLI_CONV_UTF8, (char *)mysql_stmt_error(stmt->stmt));
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_init(object link)
+/* {{{ proto mixed mysqli_stmt_init(object link) U
Initialize statement object
*/
PHP_FUNCTION(mysqli_stmt_init)
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_prepare(object stmt, string query)
+/* {{{ proto bool mysqli_stmt_prepare(object stmt, string query) U
prepare server side statement with query
*/
PHP_FUNCTION(mysqli_stmt_prepare)
{
- MY_STMT *stmt;
- zval *mysql_stmt;
- char *query;
- int query_len;
+ MY_STMT *stmt;
+ zval *mysql_stmt;
+ MYSQLI_STRING query;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry, &query, &query_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry, MYSQLI_GET_STRING(query)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_INITIALIZED);
+ MYSQLI_CONVERT_PARAM_STRING(query, MYSQLI_CONV_UTF8);
- if (mysql_stmt_prepare(stmt->stmt, query, query_len)) {
+ if (mysql_stmt_prepare(stmt->stmt, query.buf, query.buflen)) {
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end;
}
/* change status */
MYSQLI_SET_STATUS(&mysql_stmt, MYSQLI_STATUS_VALID);
- RETURN_TRUE;
+ RETVAL_TRUE;
+end:
+ MYSQLI_FREE_STRING(query);
}
/* }}} */
-/* {{{ proto mixed mysqli_stmt_result_metadata(object stmt)
+/* {{{ proto mixed mysqli_stmt_result_metadata(object stmt) U
return result set from statement */
PHP_FUNCTION(mysqli_stmt_result_metadata)
{
}
/* }}} */
-/* {{{ proto bool mysqli_stmt_store_result(stmt)
+/* {{{ proto bool mysqli_stmt_store_result(stmt) U
*/
PHP_FUNCTION(mysqli_stmt_store_result)
{
}
/* }}} */
-/* {{{ proto string mysqli_stmt_sqlstate(object stmt)
+/* {{{ proto string mysqli_stmt_sqlstate(object stmt) U
*/
PHP_FUNCTION(mysqli_stmt_sqlstate)
{
}
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
- RETURN_STRING((char *)mysql_stmt_sqlstate(stmt->stmt),1);
+ MYSQLI_RETURN_CONV_STRING(MYSQLI_CONV_ASCII, (char *)mysql_stmt_sqlstate(stmt->stmt));
}
/* }}} */
-/* {{{ proto object mysqli_store_result(object link)
+/* {{{ proto object mysqli_store_result(object link) U
Buffer result set on client */
PHP_FUNCTION(mysqli_store_result)
{
}
/* }}} */
-/* {{{ proto int mysqli_thread_id(object link)
+/* {{{ proto int mysqli_thread_id(object link) U
Return the current thread ID */
PHP_FUNCTION(mysqli_thread_id)
{
}
/* }}} */
-/* {{{ proto bool mysqli_thread_safe(void)
+/* {{{ proto bool mysqli_thread_safe(void) U
Return whether thread safety is given or not */
PHP_FUNCTION(mysqli_thread_safe)
{
/* }}} */
-/* {{{ proto mixed mysqli_use_result(object link)
+/* {{{ proto mixed mysqli_use_result(object link) U
Directly retrieve query results - do not buffer results on client side */
PHP_FUNCTION(mysqli_use_result)
{
}
/* }}} */
-/* {{{ proto int mysqli_warning_count (object link)
+/* {{{ proto int mysqli_warning_count (object link) U
Return number of warnings from the last query for the given link */
PHP_FUNCTION(mysqli_warning_count)
{
#include "ext/standard/info.h"
#include "php_mysqli.h"
-/* {{{ proto object mysqli_connect([string hostname [,string username [,string passwd [,string dbname [,int port [,string socket]]]]]])
+/* {{{ proto object mysqli_connect([string hostname [,string username [,string passwd [,string dbname [,int port [,string socket]]]]]]) U
Open a connection to a mysql server */
PHP_FUNCTION(mysqli_connect)
{
MY_MYSQL *mysql;
MYSQLI_RESOURCE *mysqli_resource;
zval *object = getThis();
- char *hostname = NULL, *username=NULL, *passwd=NULL, *dbname=NULL, *socket=NULL;
- unsigned int hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
+ MYSQLI_STRING hostname, username, passwd, dbname, socket;
long port=0;
if (getThis() && !ZEND_NUM_ARGS()) {
RETURN_NULL();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssssls", &hostname, &hostname_len, &username, &username_len,
- &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len) == FAILURE) {
+ /* optional MYSQLI_STRING parameters have to be initialized */
+ memset(&hostname, 0, sizeof(MYSQLI_STRING));
+ memset(&username, 0, sizeof(MYSQLI_STRING));
+ memset(&dbname, 0, sizeof(MYSQLI_STRING));
+ memset(&passwd, 0, sizeof(MYSQLI_STRING));
+ memset(&socket, 0, sizeof(MYSQLI_STRING));
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|TTTTlT", MYSQLI_GET_STRING(hostname), MYSQLI_GET_STRING(username),
+ MYSQLI_GET_STRING(passwd), MYSQLI_GET_STRING(dbname), &port, MYSQLI_GET_STRING(socket)) == FAILURE) {
return;
}
- if (!socket_len) {
- socket = NULL;
- }
-
- /* TODO: safe mode handling */
- if (PG(sql_safe_mode)){
- } else {
- if (!passwd) {
- passwd = MyG(default_pw);
- if (!username){
- username = MyG(default_user);
- if (!hostname) {
- hostname = MyG(default_host);
- }
- }
- }
+ /* load defaults */
+ if (!socket.buflen) {
+ socket.buf = NULL;
}
+ /* convert strings */
+ MYSQLI_CONVERT_PARAM_STRING(hostname, MYSQLI_CONV_ASCII);
+ MYSQLI_CONVERT_PARAM_STRING(username, MYSQLI_CONV_UTF8);
+ MYSQLI_CONVERT_PARAM_STRING(passwd, MYSQLI_CONV_UTF8);
+ MYSQLI_CONVERT_PARAM_STRING(dbname, MYSQLI_CONV_UTF8);
+ MYSQLI_CONVERT_PARAM_STRING(socket, MYSQLI_CONV_ASCII);
+
mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL));
if (!(mysql->mysql = mysql_init(NULL))) {
efree(mysql);
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end;
}
#ifdef HAVE_EMBEDDED_MYSQLI
- if (hostname_len && hostname) {
+ if (hostname.cbuffer_len) {
unsigned int external=1;
mysql_options(mysql->mysql, MYSQL_OPT_USE_REMOTE_CONNECTION, (char *)&external);
} else {
}
#endif
- if (!socket) {
- socket = MyG(default_socket);
- }
-
- if (mysql_real_connect(mysql->mysql,hostname,username,passwd,dbname,port,socket,CLIENT_MULTI_RESULTS) == NULL) {
+ if (mysql_real_connect(mysql->mysql, (char *)hostname.buf, (char *)username.buf, (char *)passwd.buf, (char *)dbname.buf, port,
+ (char *)socket.buf, CLIENT_MULTI_RESULTS) == NULL) {
/* Save error messages */
php_mysqli_throw_sql_exception( mysql->mysql->net.sqlstate, mysql->mysql->net.last_errno TSRMLS_CC,
/* free mysql structure */
mysql_close(mysql->mysql);
efree(mysql);
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end;
+ }
+
+ /* when PHP runs in unicode, set default character set to utf8 */
+ if (UG(unicode)) {
+ mysql_set_character_set(mysql->mysql, "utf8");
+ mysql->conv = MYSQLI_CONV_UTF8;
}
+
/* clear error */
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
} else {
((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr = mysqli_resource;
}
+end:
+ MYSQLI_FREE_STRING(hostname);
+ MYSQLI_FREE_STRING(username);
+ MYSQLI_FREE_STRING(passwd);
+ MYSQLI_FREE_STRING(dbname);
+ MYSQLI_FREE_STRING(socket);
}
/* }}} */
-/* {{{ proto int mysqli_connect_errno(void)
+/* {{{ proto int mysqli_connect_errno(void) U
Returns the numerical value of the error message from last connect command */
PHP_FUNCTION(mysqli_connect_errno)
{
}
/* }}} */
-/* {{{ proto string mysqli_connect_error(void)
+/* {{{ proto string mysqli_connect_error(void) U
Returns the text of the error message from previous MySQL operation */
PHP_FUNCTION(mysqli_connect_error)
{
if (MyG(error_msg)) {
- RETURN_STRING(MyG(error_msg),1);
+ if (UG(unicode)) {
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *ustr;
+ int ulen;
+
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, MyG(error_msg), strlen(MyG(error_msg)));
+ RETURN_UNICODEL(ustr, ulen, 0);
+ } else {
+ RETURN_STRING(MyG(error_msg),1);
+ }
} else {
RETURN_NULL();
}
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_array (object result [,int resulttype])
+/* {{{ proto mixed mysqli_fetch_array (object result [,int resulttype]) U
Fetch a result row as an associative array, a numeric array, or both */
PHP_FUNCTION(mysqli_fetch_array)
{
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_assoc (object result)
+/* {{{ proto mixed mysqli_fetch_assoc (object result) U
Fetch a result row as an associative array */
PHP_FUNCTION(mysqli_fetch_assoc)
{
}
/* }}} */
-/* {{{ proto mixed mysqli_fetch_object (object result [, string class_name [, NULL|array ctor_params]])
+/* {{{ proto mixed mysqli_fetch_object (object result [, string class_name [, NULL|array ctor_params]])
Fetch a result row as an object */
PHP_FUNCTION(mysqli_fetch_object)
{
}
/* }}} */
-/* {{{ proto bool mysqli_multi_query(object link, string query)
- Binary-safe version of mysql_query() */
+/* {{{ proto bool mysqli_multi_query(object link, string query) U
+ allows to execute multiple queries */
PHP_FUNCTION(mysqli_multi_query)
{
MY_MYSQL *mysql;
zval *mysql_link;
- char *query = NULL;
- unsigned int query_len;
+ MYSQLI_STRING query;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, MYSQLI_GET_STRING(query)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
+ MYSQLI_CONVERT_PARAM_STRING(query, MYSQLI_CONV_UTF8);
MYSQLI_ENABLE_MQ;
- if (mysql_real_query(mysql->mysql, query, query_len)) {
+ if (mysql_real_query(mysql->mysql, (char *)query.buf, query.buflen)) {
char s_error[MYSQL_ERRMSG_SIZE], s_sqlstate[SQLSTATE_LENGTH+1];
unsigned int s_errno;
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
strcpy(mysql->mysql->net.sqlstate, s_sqlstate);
mysql->mysql->net.last_errno = s_errno;
- RETURN_FALSE;
- }
- RETURN_TRUE;
+ RETVAL_FALSE;
+ } else {
+ RETVAL_TRUE;
+ }
+ MYSQLI_FREE_STRING(query);
}
/* }}} */
-/* {{{ proto mixed mysqli_query(object link, string query [,int resultmode]) */
+/* {{{ proto mixed mysqli_query(object link, string query [,int resultmode]) U */
PHP_FUNCTION(mysqli_query)
{
MY_MYSQL *mysql;
zval *mysql_link;
MYSQLI_RESOURCE *mysqli_resource;
MYSQL_RES *result;
- char *query = NULL;
- unsigned int query_len;
+ MYSQLI_STRING query;
unsigned long resultmode = MYSQLI_STORE_RESULT;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|l", &mysql_link, mysqli_link_class_entry, &query, &query_len, &resultmode) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OT|l", &mysql_link, mysqli_link_class_entry, MYSQLI_GET_STRING(query),
+ &resultmode) == FAILURE) {
return;
}
- if (!query_len) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty query");
- RETURN_FALSE;
- }
if (resultmode != MYSQLI_USE_RESULT && resultmode != MYSQLI_STORE_RESULT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for resultmode");
RETURN_FALSE;
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL*, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
+ MYSQLI_CONVERT_PARAM_STRING(query, MYSQLI_CONV_UTF8);
+
+ if (!query.buflen) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty query");
+ RETVAL_FALSE;
+ goto end;
+ }
MYSQLI_DISABLE_MQ;
- if (mysql_real_query(mysql->mysql, query, query_len)) {
+ if (mysql_real_query(mysql->mysql, (char *)query.buf, query.buflen)) {
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end;
}
if (!mysql_field_count(mysql->mysql)) {
/* no result set - not a SELECT */
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
- php_mysqli_report_index(query, mysql->mysql->server_status TSRMLS_CC);
+ php_mysqli_report_index(query.buf, mysql->mysql->server_status TSRMLS_CC);
}
- RETURN_TRUE;
+ RETVAL_TRUE;
+ goto end;
}
result = (resultmode == MYSQLI_USE_RESULT) ? mysql_use_result(mysql->mysql) : mysql_store_result(mysql->mysql);
if (!result) {
php_mysqli_throw_sql_exception(mysql->mysql->net.sqlstate, mysql->mysql->net.last_errno TSRMLS_CC,
"%s", mysql->mysql->net.last_error);
- RETURN_FALSE;
+ RETVAL_FALSE;
+ goto end;
}
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
- php_mysqli_report_index(query, mysql->mysql->server_status TSRMLS_CC);
+ php_mysqli_report_index((char *)query.buf, mysql->mysql->server_status TSRMLS_CC);
}
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = (void *)result;
mysqli_resource->status = MYSQLI_STATUS_VALID;
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
+end:
+ MYSQLI_FREE_STRING(query);
}
/* }}} */
-/* {{{ proto object mysqli_get_warnings(object link) */
+/* {{{ proto object mysqli_get_warnings(object link) U */
PHP_FUNCTION(mysqli_get_warnings)
{
MY_MYSQL *mysql;
}
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = mysqli_resource->info = (void *)w;
+ mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
}
/* }}} */
-/* {{{ proto object mysqli_get_warnings(object link) */
+/* {{{ proto object mysqli_get_warnings(object link) U */
PHP_FUNCTION(mysqli_stmt_get_warnings)
{
MY_STMT *stmt;
}
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = mysqli_resource->info = (void *)w;
- MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
+ mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
+ MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
}
/* }}} */
#ifdef HAVE_MYSQLI_SET_CHARSET
-/* {{{ proto bool mysqli_set_charset(object link, string csname)
+/* {{{ proto bool mysqli_set_charset(object link, string csname) U
sets client character set */
PHP_FUNCTION(mysqli_set_charset)
{
MY_MYSQL *mysql;
zval *mysql_link;
- char *cs_name = NULL;
- unsigned int len;
+ MYSQLI_STRING csname;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &cs_name, &len) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, MYSQLI_GET_STRING(csname)) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL*, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
+ MYSQLI_CONVERT_PARAM_STRING(csname, MYSQLI_CONV_UTF8);
+ RETVAL_FALSE;
+
+ /* check unicode modus */
+ /* todo: we need also to support UCS2. This will not work when using SET NAMES */
+ if (UG(unicode) && (csname.buflen != 4 || strncasecmp((char *)csname.buf, "utf8", 4))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Character set %s is not supported when running PHP with unicode.semantics=On.", csname);
+ RETVAL_FALSE;
+ goto end;
+ }
- if (mysql_set_character_set(mysql->mysql, cs_name)) {
- RETURN_FALSE;
+ if (!mysql_set_character_set(mysql->mysql, (char *)csname.buf)) {
+ RETVAL_TRUE;
}
- RETURN_TRUE;
+end:
+ MYSQLI_FREE_STRING(csname);
}
/* }}} */
#endif
#ifdef HAVE_MYSQLI_GET_CHARSET
-/* {{{ proto object mysqli_get_charset(object link)
+/* {{{ proto object mysqli_get_charset(object link) U
returns a character set object */
PHP_FUNCTION(mysqli_get_charset)
{
mysql_get_character_set_info(mysql->mysql, &cs);
- add_property_string(return_value, "charset", (cs.name) ? (char *)cs.csname : "", 1);
- add_property_string(return_value, "collation",(cs.name) ? (char *)cs.name : "", 1);
- add_property_string(return_value, "comment", (cs.comment) ? (char *)cs.comment : "", 1);
- add_property_string(return_value, "dir", (cs.dir) ? (char *)cs.dir : "", 1);
+ if (UG(unicode)) {
+ UErrorCode status = U_ZERO_ERROR;
+ UChar *ustr;
+ int ulen;
+
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (cs.csname) ? cs.csname : "",
+ (cs.csname) ? strlen(cs.csname) : 0);
+ add_property_unicodel(return_value, "charset", ustr, ulen, 1);
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (cs.name) ? cs.name : "",
+ (cs.name) ? strlen(cs.name) : 0);
+ add_property_unicodel(return_value, "collation", ustr, ulen, 1);
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (cs.comment) ? cs.comment : "",
+ (cs.comment) ? strlen(cs.comment) : 0);
+ add_property_unicodel(return_value, "comment", ustr, ulen, 1);
+ zend_string_to_unicode(MYSQLI_CONV_UTF8, &ustr, &ulen, (cs.dir) ? cs.dir : "",
+ (cs.dir) ? strlen(cs.dir) : 0);
+ add_property_unicodel(return_value, "dir", ustr, ulen, 1);
+ } else {
+ add_property_string(return_value, "charset", (cs.name) ? (char *)cs.csname : "", 1);
+ add_property_string(return_value, "collation",(cs.name) ? (char *)cs.name : "", 1);
+ add_property_string(return_value, "comment", (cs.comment) ? (char *)cs.comment : "", 1);
+ add_property_string(return_value, "dir", (cs.dir) ? (char *)cs.dir : "", 1);
+ }
add_property_long(return_value, "min_length", cs.mbminlen);
add_property_long(return_value, "max_length", cs.mbmaxlen);
add_property_long(return_value, "number", cs.number);