2003-02-12 08:45:53 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2003-02-22 15:31:01 +08:00
|
|
|
| PHP Version 5 |
|
2003-02-12 08:45:53 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| Copyright (c) 1997-2004 The PHP Group |
|
2003-02-12 08:45:53 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2003-06-11 04:04:29 +08:00
|
|
|
| This source file is subject to version 3.0 of the PHP license, |
|
2003-02-12 08:45:53 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_0.txt. |
|
2003-02-12 08:45:53 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Georg Richter <georg@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "ext/standard/info.h"
|
|
|
|
#include "php_mysqli.h"
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto mixed mysqli_affected_rows(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get number of affected rows in previous MySQL operation */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_affected_rows)
|
|
|
|
{
|
2003-02-16 20:03:37 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-03-09 07:33:12 +08:00
|
|
|
my_ulonglong rc;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
2003-12-13 08:28:21 +08:00
|
|
|
return;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-16 20:03:37 +08:00
|
|
|
rc = mysql_affected_rows(mysql);
|
2003-02-16 23:56:57 +08:00
|
|
|
MYSQLI_RETURN_LONG_LONG(rc);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_autocommit(object link, bool mode)
|
2003-03-16 06:51:49 +08:00
|
|
|
Turn auto commit on or of */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_autocommit)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
unsigned long rc;
|
|
|
|
unsigned long automode;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ob", &mysql_link, mysqli_link_class_entry, &automode) == FAILURE) {
|
2003-12-13 08:28:21 +08:00
|
|
|
return;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
rc = (long) mysql_autocommit(mysql, automode);
|
|
|
|
|
|
|
|
RETURN_BOOL(rc);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-29 05:27:08 +08:00
|
|
|
/* {{{ proto bool mysqli_bind_param(object stmt, array types, mixed variable [,mixed,....])
|
2003-05-04 11:15:02 +08:00
|
|
|
Bind variables to a prepared statement as parameters */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_bind_param)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
zval ***args;
|
|
|
|
int argc = ZEND_NUM_ARGS();
|
|
|
|
int i;
|
|
|
|
int num_vars;
|
2003-06-29 05:27:08 +08:00
|
|
|
int start = 2;
|
2003-03-09 07:33:12 +08:00
|
|
|
int ofs;
|
|
|
|
STMT *stmt;
|
2003-06-29 05:27:08 +08:00
|
|
|
zval *mysql_stmt;
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_BIND *bind;
|
2003-06-29 05:27:08 +08:00
|
|
|
zval *types;
|
|
|
|
HashPosition hpos;
|
2003-03-09 07:33:12 +08:00
|
|
|
unsigned long rc;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-04-11 12:29:28 +08:00
|
|
|
/* calculate and check number of parameters */
|
2003-06-29 05:27:08 +08:00
|
|
|
num_vars = argc - 1;
|
2003-04-11 12:29:28 +08:00
|
|
|
if (!getThis()) {
|
|
|
|
/* ignore handle parameter in procedural interface*/
|
|
|
|
--num_vars;
|
|
|
|
}
|
2003-06-29 05:27:08 +08:00
|
|
|
if (argc < 2) {
|
2003-04-11 12:29:28 +08:00
|
|
|
/* there has to be at least one pair */
|
2003-02-12 08:45:53 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2003-06-29 05:27:08 +08:00
|
|
|
if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Oa", &mysql_stmt, mysqli_stmt_class_entry, &types) == FAILURE) {
|
|
|
|
return;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-06-29 05:27:08 +08:00
|
|
|
|
|
|
|
if (getThis()) {
|
2003-02-12 08:45:53 +08:00
|
|
|
start = 1;
|
|
|
|
}
|
|
|
|
|
2003-06-29 05:27:08 +08:00
|
|
|
if (zend_hash_num_elements(Z_ARRVAL_P(types)) != argc - start) {
|
|
|
|
/* number of bind variables doesn't match number of elements in array */
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements in type array doesn't match number of bind variables");
|
2003-07-28 18:23:36 +08:00
|
|
|
}
|
2003-07-15 18:37:19 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
/* prevent leak if variables are already bound */
|
2003-07-15 18:37:19 +08:00
|
|
|
if (stmt->param.var_cnt) {
|
|
|
|
php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-07-15 18:37:19 +08:00
|
|
|
|
2003-08-12 08:58:52 +08:00
|
|
|
args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
|
2003-06-29 05:27:08 +08:00
|
|
|
|
|
|
|
if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
|
|
|
|
efree(args);
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2003-04-11 12:41:52 +08:00
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->param.is_null = ecalloc(num_vars, sizeof(char));
|
2003-02-12 08:45:53 +08:00
|
|
|
bind = (MYSQL_BIND *)ecalloc(num_vars, sizeof(MYSQL_BIND));
|
|
|
|
|
2003-06-29 05:27:08 +08:00
|
|
|
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(types), &hpos);
|
|
|
|
|
|
|
|
ofs = 0;
|
|
|
|
for (i=start; i < argc; i++) {
|
|
|
|
zval **ctype;
|
|
|
|
|
|
|
|
zend_hash_get_current_data_ex(Z_ARRVAL_P(types), (void **)&ctype, &hpos);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
/* set specified type */
|
2003-06-29 05:27:08 +08:00
|
|
|
switch (Z_LVAL_PP(ctype)) {
|
2003-02-12 08:45:53 +08:00
|
|
|
case MYSQLI_BIND_DOUBLE:
|
|
|
|
bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
|
|
|
|
bind[ofs].buffer = (gptr)&Z_DVAL_PP(args[i]);
|
2003-07-15 18:37:19 +08:00
|
|
|
bind[ofs].is_null = &stmt->param.is_null[ofs];
|
2003-02-12 08:45:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MYSQLI_BIND_INT:
|
|
|
|
bind[ofs].buffer_type = MYSQL_TYPE_LONG;
|
|
|
|
bind[ofs].buffer = (gptr)&Z_LVAL_PP(args[i]);
|
2003-07-15 18:37:19 +08:00
|
|
|
bind[ofs].is_null = &stmt->param.is_null[ofs];
|
2003-02-12 08:45:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MYSQLI_BIND_SEND_DATA:
|
|
|
|
bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING;
|
|
|
|
bind[ofs].is_null = 0;
|
|
|
|
bind[ofs].length = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MYSQLI_BIND_STRING:
|
|
|
|
bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING;
|
2003-02-22 15:47:46 +08:00
|
|
|
bind[ofs].buffer = NULL;
|
|
|
|
bind[ofs].buffer_length = 0;
|
2003-07-15 18:37:19 +08:00
|
|
|
bind[ofs].is_null = &stmt->param.is_null[ofs];
|
2003-02-12 08:45:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-08-29 05:00:24 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %ld (parameter %d)", Z_LVAL_PP(args[i]), i+1);
|
2003-02-12 08:45:53 +08:00
|
|
|
efree(args);
|
|
|
|
efree(bind);
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2003-06-29 05:27:08 +08:00
|
|
|
ofs++;
|
|
|
|
zend_hash_move_forward_ex(Z_ARRVAL_P(types), &hpos);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
rc = mysql_bind_param(stmt->stmt, bind);
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
|
2003-03-09 07:33:12 +08:00
|
|
|
|
|
|
|
if (rc) {
|
2003-02-15 00:49:09 +08:00
|
|
|
efree(args);
|
2003-02-12 08:45:53 +08:00
|
|
|
efree(bind);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->param.var_cnt = num_vars;
|
2003-08-12 08:58:52 +08:00
|
|
|
stmt->param.vars = (zval **)safe_emalloc(num_vars, sizeof(zval), 0);
|
2003-06-29 05:27:08 +08:00
|
|
|
for (i = 0; i < num_vars; i++) {
|
|
|
|
if (bind[i].buffer_type != MYSQLI_BIND_SEND_DATA) {
|
2003-02-12 08:45:53 +08:00
|
|
|
ZVAL_ADDREF(*args[i+start]);
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->param.vars[i] = *args[i+start];
|
2003-02-15 00:49:09 +08:00
|
|
|
} else {
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->param.vars[i] = NULL;
|
2003-02-15 00:49:09 +08:00
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
efree(args);
|
|
|
|
efree(bind);
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-12-29 06:26:59 +08:00
|
|
|
/* {{{ proto bool mysqli_bind_result(object stmt, mixed var, [,mixed, ...])
|
2003-05-04 11:15:02 +08:00
|
|
|
Bind variables to a prepared statement for result storage */
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
do_alloca, free_alloca
|
|
|
|
*/
|
|
|
|
|
|
|
|
PHP_FUNCTION(mysqli_bind_result)
|
|
|
|
{
|
|
|
|
zval ***args;
|
|
|
|
int argc = ZEND_NUM_ARGS();
|
|
|
|
int i;
|
2003-06-29 05:27:08 +08:00
|
|
|
int start = 1;
|
2003-03-09 07:33:12 +08:00
|
|
|
int var_cnt;
|
|
|
|
int ofs;
|
2003-02-12 08:45:53 +08:00
|
|
|
long col_type;
|
2003-03-09 07:33:12 +08:00
|
|
|
ulong rc;
|
2003-02-12 08:45:53 +08:00
|
|
|
STMT *stmt;
|
2003-06-29 05:27:08 +08:00
|
|
|
zval *mysql_stmt;
|
2003-02-12 08:45:53 +08:00
|
|
|
MYSQL_BIND *bind;
|
|
|
|
|
2003-04-11 12:29:28 +08:00
|
|
|
if (argc < (getThis() ? 1 : 2)) {
|
2003-02-12 08:45:53 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2003-06-29 05:27:08 +08:00
|
|
|
|
2003-08-12 08:58:52 +08:00
|
|
|
args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
|
|
|
|
efree(args);
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2003-06-29 05:27:08 +08:00
|
|
|
if (getThis()) {
|
|
|
|
start = 0;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-06-29 05:27:08 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters((getThis()) ? 0:1 TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
var_cnt = argc - start;
|
|
|
|
|
|
|
|
/* prevent leak if variables are already bound */
|
2003-07-15 18:37:19 +08:00
|
|
|
if (stmt->result.var_cnt) {
|
|
|
|
php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bind = (MYSQL_BIND *)ecalloc(var_cnt, sizeof(MYSQL_BIND));
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.buf = (VAR_BUFFER *)ecalloc(var_cnt,sizeof(VAR_BUFFER));
|
|
|
|
stmt->result.is_null = (char *)ecalloc(var_cnt, sizeof(char));
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
for (i=start; i < var_cnt + start ; i++) {
|
|
|
|
ofs = i - start;
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.is_null[ofs] = 0;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
col_type = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].type : MYSQL_TYPE_STRING;
|
|
|
|
|
|
|
|
switch (col_type) {
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
convert_to_double_ex(args[i]);
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.buf[ofs].type = IS_DOUBLE;
|
|
|
|
stmt->result.buf[ofs].buflen = 0;
|
2003-02-12 08:45:53 +08:00
|
|
|
bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
|
|
|
|
bind[ofs].buffer = (gptr)&Z_DVAL_PP(args[i]);
|
2003-07-15 18:37:19 +08:00
|
|
|
bind[ofs].is_null = &stmt->result.is_null[ofs];
|
2003-02-12 08:45:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
case MYSQL_TYPE_INT24:
|
|
|
|
case MYSQL_TYPE_YEAR:
|
|
|
|
convert_to_long_ex(args[i]);
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.buf[ofs].type = IS_LONG;
|
|
|
|
stmt->result.buf[ofs].buflen = 0;
|
2003-02-12 08:45:53 +08:00
|
|
|
bind[ofs].buffer_type = MYSQL_TYPE_LONG;
|
|
|
|
bind[ofs].buffer = (gptr)&Z_LVAL_PP(args[i]);
|
2003-07-15 18:37:19 +08:00
|
|
|
bind[ofs].is_null = &stmt->result.is_null[ofs];
|
2003-02-12 08:45:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
2003-07-15 18:37:19 +08:00
|
|
|
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);
|
2003-02-12 08:45:53 +08:00
|
|
|
bind[ofs].buffer_type = MYSQL_TYPE_LONGLONG;
|
2003-07-15 18:37:19 +08:00
|
|
|
bind[ofs].buffer = stmt->result.buf[ofs].buffer;
|
|
|
|
bind[ofs].is_null = &stmt->result.is_null[ofs];
|
|
|
|
bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
|
2003-02-12 08:45:53 +08:00
|
|
|
break;
|
2003-07-15 18:37:19 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
case MYSQL_TYPE_DATE:
|
|
|
|
case MYSQL_TYPE_TIME:
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
case MYSQL_TYPE_NEWDATE:
|
|
|
|
case MYSQL_TYPE_VAR_STRING:
|
|
|
|
case MYSQL_TYPE_STRING:
|
|
|
|
case MYSQL_TYPE_BLOB:
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
2004-01-31 15:51:03 +08:00
|
|
|
case MYSQL_TYPE_DECIMAL:
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.buf[ofs].type = IS_STRING;
|
|
|
|
stmt->result.buf[ofs].buflen = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].length + 1: 256;
|
|
|
|
stmt->result.buf[ofs].buffer = (char *)emalloc(stmt->result.buf[ofs].buflen);
|
2003-02-12 08:45:53 +08:00
|
|
|
bind[ofs].buffer_type = MYSQL_TYPE_STRING;
|
2003-07-15 18:37:19 +08:00
|
|
|
bind[ofs].buffer = stmt->result.buf[ofs].buffer;
|
|
|
|
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;
|
2003-02-12 08:45:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
rc = mysql_bind_result(stmt->stmt, bind);
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
|
2003-03-09 07:33:12 +08:00
|
|
|
|
|
|
|
if (rc) {
|
2003-02-12 08:45:53 +08:00
|
|
|
efree(bind);
|
|
|
|
efree(args);
|
|
|
|
php_clear_stmt_bind(stmt);
|
2003-02-15 00:49:09 +08:00
|
|
|
RETURN_FALSE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.var_cnt = var_cnt;
|
2003-08-12 08:58:52 +08:00
|
|
|
stmt->result.vars = (zval **)safe_emalloc((var_cnt), sizeof(zval), 0);
|
2003-02-12 08:45:53 +08:00
|
|
|
for (i = start; i < var_cnt+start; i++) {
|
|
|
|
ofs = i-start;
|
|
|
|
ZVAL_ADDREF(*args[i]);
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.vars[ofs] = *args[i];
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
efree(args);
|
|
|
|
efree(bind);
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_change_user(object link, string user, string password, string database)
|
2003-05-04 11:15:02 +08:00
|
|
|
Change logged-in user of the active connection */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_change_user)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link = NULL;
|
|
|
|
char *user, *password, *dbname;
|
|
|
|
int user_len, password_len, dbname_len;
|
|
|
|
ulong rc;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
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) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
rc = mysql_change_user(mysql, user, password, dbname);
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
if (rc) {
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_character_set_name(object link)
|
2003-05-04 11:15:02 +08:00
|
|
|
Returns the name of the character set used for this connection */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_character_set_name)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
char *charsetname;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-03-09 07:33:12 +08:00
|
|
|
|
|
|
|
charsetname = (char *)mysql_character_set_name(mysql);
|
|
|
|
|
|
|
|
RETURN_STRING(charsetname, 1);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_close(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Close connection */
|
2003-02-15 00:49:09 +08:00
|
|
|
PHP_FUNCTION(mysqli_close)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
zval *mysql_link;
|
|
|
|
MYSQL *mysql;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-18 08:00:51 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
mysql_close(mysql);
|
2003-03-09 07:33:12 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
MYSQLI_CLEAR_RESOURCE(&mysql_link);
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_commit(object link)
|
2003-05-04 11:15:02 +08:00
|
|
|
Commit outstanding actions and close transaction */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_commit)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
ulong rc;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-03-09 07:33:12 +08:00
|
|
|
rc = mysql_commit(mysql);
|
|
|
|
RETURN_BOOL(rc);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-27 21:56:03 +08:00
|
|
|
/* {{{ proto bool mysqli_data_seek(object result, int offset)
|
2003-03-16 06:51:49 +08:00
|
|
|
Move internal result pointer */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_data_seek)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
|
|
|
long offset;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-07-15 22:00:19 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
|
2003-02-12 08:45:53 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT) {
|
2003-02-15 00:49:09 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
|
2004-01-27 21:56:03 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-01-29 06:51:54 +08:00
|
|
|
if (offset < 0 || offset >= result->row_count) {
|
2004-01-27 21:56:03 +08:00
|
|
|
RETURN_FALSE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
mysql_data_seek(result, offset);
|
2004-01-27 21:56:03 +08:00
|
|
|
RETURN_TRUE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void mysqli_debug(string debug)
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_debug)
|
|
|
|
{
|
2003-03-11 09:19:21 +08:00
|
|
|
char *debug;
|
|
|
|
int debug_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &debug, &debug_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mysql_debug(debug);
|
2003-02-15 04:14:44 +08:00
|
|
|
RETURN_TRUE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto void mysqli_disable_reads_from_master(object link)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
2003-02-15 00:49:09 +08:00
|
|
|
PHP_FUNCTION(mysqli_disable_reads_from_master)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-15 04:14:44 +08:00
|
|
|
mysql_disable_reads_from_master(mysql);
|
|
|
|
RETURN_TRUE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto void mysqli_disable_rpl_parse(object link)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
2003-02-15 00:49:09 +08:00
|
|
|
PHP_FUNCTION(mysqli_disable_rpl_parse)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-15 04:14:44 +08:00
|
|
|
mysql_disable_rpl_parse(mysql);
|
|
|
|
RETURN_TRUE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_dump_debug_info(object link)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_dump_debug_info)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
ulong rc;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-03-09 07:33:12 +08:00
|
|
|
|
|
|
|
rc = mysql_dump_debug_info(mysql);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
if (rc) {
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto void mysqli_enable_reads_from_master(object link)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
2003-02-15 00:49:09 +08:00
|
|
|
PHP_FUNCTION(mysqli_enable_reads_from_master)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-15 04:14:44 +08:00
|
|
|
mysql_enable_reads_from_master(mysql);
|
|
|
|
RETURN_TRUE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto void mysqli_enable_rpl_parse(object link)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
2003-02-15 00:49:09 +08:00
|
|
|
PHP_FUNCTION(mysqli_enable_rpl_parse)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-18 11:12:38 +08:00
|
|
|
mysql_enable_rpl_parse(mysql);
|
|
|
|
RETURN_TRUE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_errno(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Returns the numerical value of the error message from previous MySQL operation */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_errno)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_LONG(mysql_errno(mysql));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_error(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Returns the text of the error message from previous MySQL operation */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_error)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_STRING((char *)mysql_error(mysql),1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-10-30 20:35:16 +08:00
|
|
|
/* {{{ proto bool mysqli_execute(object stmt)
|
2003-05-04 11:15:02 +08:00
|
|
|
Execute a prepared statement */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_execute)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
|
|
|
unsigned int i;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
for (i = 0; i < stmt->param.var_cnt; i++) {
|
|
|
|
if (stmt->param.vars[i]) {
|
|
|
|
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 = strlen(Z_STRVAL_PP(&stmt->param.vars[i]));
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
convert_to_double_ex(&stmt->param.vars[i]);
|
|
|
|
stmt->stmt->params[i].buffer = (gptr)&Z_LVAL_PP(&stmt->param.vars[i]);
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
convert_to_long_ex(&stmt->param.vars[i]);
|
|
|
|
stmt->stmt->params[i].buffer = (gptr)&Z_LVAL_PP(&stmt->param.vars[i]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-30 20:35:16 +08:00
|
|
|
if (mysql_execute(stmt->stmt)) {
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
|
2003-10-30 20:35:16 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-12-16 16:18:31 +08:00
|
|
|
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
|
|
|
|
php_mysqli_report_index(stmt->stmt->query, stmt->stmt->mysql->server_status TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
2003-10-30 20:35:16 +08:00
|
|
|
RETURN_TRUE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-25 20:01:36 +08:00
|
|
|
/* {{{ proto mixed mysqli_fetch(object stmt)
|
2003-05-04 11:15:02 +08:00
|
|
|
Fetch results from a prepared statement into the bound variables */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_fetch)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
|
|
|
unsigned int i;
|
|
|
|
ulong ret;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
/* reset buffers */
|
|
|
|
|
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
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);
|
2003-02-15 00:49:09 +08:00
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
if (!(ret = mysql_fetch(stmt->stmt))) {
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
for (i = 0; i < stmt->result.var_cnt; i++) {
|
|
|
|
if (!stmt->result.is_null[i]) {
|
|
|
|
switch (stmt->result.buf[i].type) {
|
2003-02-15 02:17:25 +08:00
|
|
|
case IS_LONG:
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.vars[i]->type = IS_LONG;
|
2003-02-15 02:17:25 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.vars[i]->type = IS_DOUBLE;
|
2003-02-15 02:17:25 +08:00
|
|
|
break;
|
|
|
|
case IS_STRING:
|
|
|
|
if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_LONGLONG) {
|
|
|
|
char tmp[50];
|
|
|
|
my_ulonglong lval;
|
2003-07-15 18:37:19 +08:00
|
|
|
memcpy (&lval, stmt->result.buf[i].buffer, sizeof(my_ulonglong));
|
2003-02-15 02:17:25 +08:00
|
|
|
if (lval != (long)lval) {
|
2003-02-17 01:59:30 +08:00
|
|
|
/* even though lval is declared as unsigned, the value
|
|
|
|
* may be negative. Therefor we cannot use %llu and must
|
2004-01-25 20:01:36 +08:00
|
|
|
* use %lld.
|
2003-02-17 01:59:30 +08:00
|
|
|
*/
|
|
|
|
sprintf((char *)&tmp, "%lld", lval);
|
2003-07-15 18:37:19 +08:00
|
|
|
ZVAL_STRING(stmt->result.vars[i], tmp, 1);
|
2003-02-15 02:17:25 +08:00
|
|
|
} else {
|
2003-07-15 18:37:19 +08:00
|
|
|
ZVAL_LONG(stmt->result.vars[i], lval);
|
2003-02-15 02:17:25 +08:00
|
|
|
}
|
2003-02-15 00:49:09 +08:00
|
|
|
} else {
|
2003-07-15 18:37:19 +08:00
|
|
|
if (stmt->result.vars[i]->type == IS_STRING) {
|
|
|
|
efree(stmt->result.vars[i]->value.str.val);
|
2003-02-22 15:31:01 +08:00
|
|
|
}
|
2003-07-15 18:37:19 +08:00
|
|
|
ZVAL_STRING(stmt->result.vars[i], stmt->result.buf[i].buffer, 1);
|
2003-02-15 00:49:09 +08:00
|
|
|
}
|
2003-02-15 02:17:25 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2003-07-15 18:37:19 +08:00
|
|
|
stmt->result.vars[i]->type = IS_NULL;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-02-15 00:49:09 +08:00
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
} else {
|
|
|
|
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
2004-01-25 20:01:36 +08:00
|
|
|
switch (ret) {
|
|
|
|
case 0:
|
|
|
|
RETURN_TRUE;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
RETURN_FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
break;
|
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-26 15:39:57 +08:00
|
|
|
/* {{{ proto mixed mysqli_fetch_field (object result)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get column information from a result and return as an object */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_fetch_field)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
2003-02-12 08:45:53 +08:00
|
|
|
MYSQL_FIELD *field;
|
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (!(field = mysql_fetch_field(result))) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
object_init(return_value);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
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, "flags", field->flags);
|
|
|
|
add_property_long(return_value, "type", field->type);
|
|
|
|
add_property_long(return_value, "decimals", field->decimals);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-26 15:39:57 +08:00
|
|
|
/* {{{ proto mixed mysqli_fetch_fields (object result)
|
2003-05-04 11:15:02 +08:00
|
|
|
Return array of objects containing field meta-data */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_fetch_fields)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
|
|
|
MYSQL_FIELD *field;
|
|
|
|
zval *obj;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
unsigned int i;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (!(field = mysql_fetch_field(result))) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
array_init(return_value);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
for (i = 0; i < mysql_num_fields(result); i++) {
|
2003-02-12 08:45:53 +08:00
|
|
|
field = mysql_fetch_field_direct(result, i);
|
|
|
|
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(obj);
|
2003-02-15 00:49:09 +08:00
|
|
|
object_init(obj);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
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, "flags", field->flags);
|
|
|
|
add_property_long(obj, "type", field->type);
|
|
|
|
add_property_long(obj, "decimals", field->decimals);
|
|
|
|
|
|
|
|
add_index_zval(return_value, i, obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-26 15:39:57 +08:00
|
|
|
/* {{{ proto mixed mysqli_fetch_field_direct (object result, int offset)
|
2003-05-04 11:15:02 +08:00
|
|
|
Fetch meta-data for a single field */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_fetch_field_direct)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
2003-02-12 08:45:53 +08:00
|
|
|
MYSQL_FIELD *field;
|
2003-03-09 07:33:12 +08:00
|
|
|
int offset;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (!(field = mysql_fetch_field_direct(result,offset))) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
object_init(return_value);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
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, "flags", field->flags);
|
|
|
|
add_property_long(return_value, "type", field->type);
|
|
|
|
add_property_long(return_value, "decimals", field->decimals);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-26 15:39:57 +08:00
|
|
|
/* {{{ proto mixed mysqli_fetch_lengths (object result)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get the length of each output in a result */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_fetch_lengths)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
|
|
|
unsigned int i;
|
|
|
|
unsigned long *ret;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
if (!(ret = mysql_fetch_lengths(result))) {
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
array_init(return_value);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
for (i = 0; i < mysql_num_fields(result); i++) {
|
2003-02-12 08:45:53 +08:00
|
|
|
add_index_long(return_value, i, ret[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto array mysqli_fetch_row (object result)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get a result row as an enumerated array */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_fetch_row)
|
|
|
|
{
|
2003-09-07 03:34:48 +08:00
|
|
|
php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_NUM, 0);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_field_count(object link)
|
2003-05-04 11:15:02 +08:00
|
|
|
Fetch the number of fields returned by the last query for the given link
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_field_count)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_field_count(mysql));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-25 20:01:36 +08:00
|
|
|
/* {{{ proto int mysqli_field_seek(object result, int fieldnr)
|
2003-05-04 11:15:02 +08:00
|
|
|
Set result pointer to a specified field offset
|
|
|
|
*/
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_field_seek)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
|
|
|
unsigned int fieldnr;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &fieldnr) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (fieldnr < 0 || fieldnr >= mysql_num_fields(result)) {
|
2003-02-15 00:49:09 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field offset is invalid for resultset");
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mysql_field_seek(result, fieldnr);
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_field_tell(object result)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get current field offset of result pointer */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_field_tell)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_field_tell(result));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-29 06:51:54 +08:00
|
|
|
/* {{{ proto void mysqli_free_result(object result)
|
2003-05-04 11:15:02 +08:00
|
|
|
Free query result memory for the given result handle */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_free_result)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
mysql_free_result(result);
|
2003-02-12 08:45:53 +08:00
|
|
|
MYSQLI_CLEAR_RESOURCE(&mysql_result);
|
|
|
|
|
2004-01-29 06:51:54 +08:00
|
|
|
return;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-03-16 06:51:49 +08:00
|
|
|
/* {{{ proto string mysqli_get_client_info(void)
|
|
|
|
Get MySQL client info */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_get_client_info)
|
|
|
|
{
|
|
|
|
RETURN_STRING((char *)mysql_get_client_info(), 1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-29 06:51:54 +08:00
|
|
|
/* {{{ proto int mysqli_get_client_version(void)
|
|
|
|
Get MySQL client info */
|
|
|
|
PHP_FUNCTION(mysqli_get_client_version)
|
|
|
|
{
|
|
|
|
RETURN_LONG((long)mysql_get_client_version());
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_get_host_info (object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get MySQL host info */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_get_host_info)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link = NULL;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-12-14 00:08:13 +08:00
|
|
|
RETURN_STRING((mysql->host_info) ? mysql->host_info : empty_string, 1);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
/* {{{ proto int mysqli_get_proto_info(object link)
|
2003-05-04 11:15:02 +08:00
|
|
|
Get MySQL protocol information */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_get_proto_info)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link = NULL;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_get_proto_info(mysql));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_get_server_info(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get MySQL server info */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_get_server_info)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link = NULL;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_STRING((char *)mysql_get_server_info(mysql), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_get_server_version(object link)
|
2003-05-04 11:15:02 +08:00
|
|
|
Return the MySQL version for the server referenced by the given link */
|
2003-02-13 08:11:17 +08:00
|
|
|
PHP_FUNCTION(mysqli_get_server_version)
|
|
|
|
{
|
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link = NULL;
|
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-13 08:11:17 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_get_server_version(mysql));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_info(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get information about the most recent query */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_info)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link = NULL;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-12-14 00:08:13 +08:00
|
|
|
RETURN_STRING((mysql->info) ? mysql->info : empty_string, 1);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-03-17 20:48:38 +08:00
|
|
|
/* {{{ proto resource mysqli_init(void)
|
2003-05-04 11:15:02 +08:00
|
|
|
Initialize mysqli and return a resource for use with mysql_real_connect */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_init)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQLI_RESOURCE *mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
|
|
|
|
mysqli_resource->ptr = (void *)mysql_init(NULL);
|
|
|
|
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto mixed mysqli_insert_id(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get the ID generated from the previous INSERT operation */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_insert_id)
|
|
|
|
{
|
2003-02-16 20:03:37 +08:00
|
|
|
MYSQL *mysql;
|
2003-03-09 07:33:12 +08:00
|
|
|
my_ulonglong rc;
|
2003-02-16 20:03:37 +08:00
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
rc = mysql_insert_id(mysql);
|
2003-02-16 23:56:57 +08:00
|
|
|
MYSQLI_RETURN_LONG_LONG(rc)
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_kill(object link, int processid)
|
2003-03-16 06:51:49 +08:00
|
|
|
Kill a mysql process on the server */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_kill)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
int processid;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_link, mysqli_link_class_entry, &processid) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (mysql_kill(mysql, processid)) {
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_master_query(object link, string query)
|
2003-05-04 11:15:02 +08:00
|
|
|
Enforce execution of a query on the master in a master/slave setup */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_master_query) {
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
char *query = NULL;
|
|
|
|
unsigned int query_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (mysql_master_query(mysql, query, query_len)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
/* {{{ proto bool mysqli_more_results(object link)
|
|
|
|
check if there any more query results from a multi query */
|
|
|
|
PHP_FUNCTION(mysqli_more_results) {
|
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
|
|
|
|
if (!mysql_more_results(mysql)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool mysqli_next_result(object link)
|
|
|
|
read next result from multi_query */
|
|
|
|
PHP_FUNCTION(mysqli_next_result) {
|
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
|
|
|
|
if (mysql_next_result(mysql)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_num_fields(object result)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get number of fields in result */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_num_fields)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_num_fields(result));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-12-31 03:19:13 +08:00
|
|
|
/* {{{ proto mixed mysqli_num_rows(object result)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get number of rows in result */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_num_rows)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT) {
|
2003-02-15 00:49:09 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_LONG(0);
|
|
|
|
}
|
|
|
|
|
2003-12-31 03:19:13 +08:00
|
|
|
MYSQLI_RETURN_LONG_LONG(mysql_num_rows(result));
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_options(object link, int flags, mixed values)
|
2003-03-16 06:51:49 +08:00
|
|
|
Set options */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_options)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link = NULL;
|
|
|
|
zval *mysql_value;
|
|
|
|
long mysql_option;
|
|
|
|
unsigned int l_value;
|
|
|
|
long ret;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-08-21 22:34:07 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olz", &mysql_link, mysqli_link_class_entry, &mysql_option, &mysql_value) == FAILURE) {
|
2003-02-12 08:45:53 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
switch (Z_TYPE_PP(&mysql_value)) {
|
|
|
|
case IS_STRING:
|
|
|
|
ret = mysql_options(mysql, mysql_option, Z_STRVAL_PP(&mysql_value));
|
2003-02-15 00:49:09 +08:00
|
|
|
break;
|
2003-02-12 08:45:53 +08:00
|
|
|
default:
|
|
|
|
convert_to_long_ex(&mysql_value);
|
|
|
|
l_value = Z_LVAL_PP(&mysql_value);
|
|
|
|
ret = mysql_options(mysql, mysql_option, (char *)&l_value);
|
2003-02-15 00:49:09 +08:00
|
|
|
break;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != 0) {
|
2003-02-15 00:49:09 +08:00
|
|
|
RETURN_FALSE;
|
2003-02-12 08:45:53 +08:00
|
|
|
} else {
|
2003-02-15 00:49:09 +08:00
|
|
|
RETURN_TRUE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_param_count(object stmt) {
|
2003-03-16 06:51:49 +08:00
|
|
|
Return the number of parameter for the given statement */
|
2003-02-15 00:49:09 +08:00
|
|
|
PHP_FUNCTION(mysqli_param_count)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_param_count(stmt->stmt));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_ping(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Ping a server connection or reconnect if there is no connection */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_ping)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-12-13 08:28:21 +08:00
|
|
|
long rc;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
|
|
|
rc = mysql_ping(mysql);
|
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
|
|
|
RETURN_LONG(rc);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-27 21:23:54 +08:00
|
|
|
/* {{{ proto mixed mysqli_prepare(object link, string query)
|
2003-03-16 06:51:49 +08:00
|
|
|
Prepare a SQL statement for execution */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_prepare)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
STMT *stmt;
|
|
|
|
char *query = NULL;
|
|
|
|
unsigned int query_len;
|
|
|
|
zval *mysql_link;
|
|
|
|
MYSQLI_RESOURCE *mysqli_resource;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",&mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
stmt = (STMT *)ecalloc(1,sizeof(STMT));
|
2003-03-09 07:33:12 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
stmt->stmt = mysql_prepare(mysql, query, query_len);
|
|
|
|
|
|
|
|
if (!stmt->stmt) {
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
2003-02-12 08:45:53 +08:00
|
|
|
efree(stmt);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
|
|
|
|
mysqli_resource->ptr = (void *)stmt;
|
|
|
|
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_stmt_class_entry);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-27 21:23:54 +08:00
|
|
|
/* {{{ proto mixed mysqli_get_metadata(object stmt)
|
2003-12-13 08:28:21 +08:00
|
|
|
return result set from statement */
|
2003-09-25 19:19:25 +08:00
|
|
|
PHP_FUNCTION(mysqli_get_metadata)
|
2003-02-12 08:45:53 +08:00
|
|
|
{
|
2003-04-03 16:03:59 +08:00
|
|
|
STMT *stmt;
|
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_stmt;
|
|
|
|
MYSQLI_RESOURCE *mysqli_resource;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-09-25 19:19:25 +08:00
|
|
|
if (!(result = mysql_get_metadata(stmt->stmt))){
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-02-15 00:49:09 +08:00
|
|
|
|
2003-04-03 16:03:59 +08:00
|
|
|
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
|
|
|
|
mysqli_resource->ptr = (void *)result;
|
|
|
|
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_real_connect(object link [,string hostname [,string username [,string passwd [,string dbname [,int port [,string socket [,int flags]]]]]]])
|
2003-05-04 11:15:02 +08:00
|
|
|
Open a connection to a mysql server */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_real_connect)
|
|
|
|
{
|
2003-12-31 16:34:02 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
char *hostname = NULL, *username=NULL, *passwd=NULL, *dbname=NULL, *socket=NULL;
|
|
|
|
unsigned int hostname_len, username_len, passwd_len, dbname_len, socket_len;
|
|
|
|
unsigned int port=0, flags=0;
|
|
|
|
zval *mysql_link;
|
|
|
|
zval *object = getThis();
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
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,
|
|
|
|
&flags) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!socket_len) {
|
|
|
|
socket = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: safe mode handling */
|
2003-02-15 00:49:09 +08:00
|
|
|
if (PG(sql_safe_mode)) {
|
2003-02-12 08:45:53 +08:00
|
|
|
} else {
|
|
|
|
if (!passwd) {
|
|
|
|
passwd = MyG(default_pw);
|
|
|
|
if (!username){
|
|
|
|
username = MyG(default_user);
|
|
|
|
if (!hostname) {
|
|
|
|
hostname = MyG(default_host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-05-31 15:05:34 +08:00
|
|
|
/* remove some insecure options */
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
flags ^= CLIENT_MULTI_STATEMENTS; /* don't allow multi_queries via connect parameter */
|
2003-05-31 15:05:34 +08:00
|
|
|
if (PG(open_basedir) && strlen(PG(open_basedir))) {
|
|
|
|
flags ^= CLIENT_LOCAL_FILES;
|
|
|
|
}
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
if (mysql_real_connect(mysql,hostname,username,passwd,dbname,port,socket,flags) == NULL) {
|
2003-12-13 08:28:21 +08:00
|
|
|
|
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
|
|
|
php_mysqli_set_error(mysql_errno(mysql), (char *) mysql_error(mysql) TSRMLS_CC);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
if (!(MyG(report_mode) & MYSQLI_REPORT_ERROR)) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysql_error(mysql));
|
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-07-18 14:17:39 +08:00
|
|
|
php_mysqli_set_error(mysql_errno(mysql), (char *)mysql_error(mysql) TSRMLS_CC);
|
|
|
|
|
2003-12-31 16:34:02 +08:00
|
|
|
if (object) {
|
|
|
|
((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->valid = 1;
|
|
|
|
}
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_real_query(object link, string query)
|
2003-05-04 11:15:02 +08:00
|
|
|
Binary-safe version of mysql_query() */
|
2003-02-15 02:35:30 +08:00
|
|
|
PHP_FUNCTION(mysqli_real_query)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
char *query = NULL;
|
|
|
|
unsigned int query_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
|
|
|
|
|
|
|
MYSQLI_DISABLE_MQ; /* disable multi statements/queries */
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (mysql_real_query(mysql, query, query_len)) {
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
2003-12-13 08:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mysql_field_count(mysql)) {
|
|
|
|
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
|
2003-12-13 21:44:56 +08:00
|
|
|
php_mysqli_report_index(query, mysql->server_status TSRMLS_CC);
|
2003-12-13 08:28:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_real_escape_string(object link, string escapestr)
|
2003-03-16 06:51:49 +08:00
|
|
|
Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_real_escape_string) {
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link = NULL;
|
|
|
|
char *escapestr, *newstr;
|
|
|
|
int escapestr_len, newstr_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &escapestr, &escapestr_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-08-12 08:58:52 +08:00
|
|
|
newstr = safe_emalloc(2, escapestr_len, 1);
|
2003-02-12 08:45:53 +08:00
|
|
|
newstr_len = mysql_real_escape_string(mysql, newstr, escapestr, escapestr_len);
|
|
|
|
newstr = erealloc(newstr, newstr_len + 1);
|
|
|
|
|
|
|
|
RETURN_STRING(newstr, 0);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_rollback(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Undo actions from current transaction */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_rollback)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_BOOL(mysql_rollback(mysql));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_rpl_parse_enabled(object link)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
2003-02-15 02:35:30 +08:00
|
|
|
PHP_FUNCTION(mysqli_rpl_parse_enabled)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_rpl_parse_enabled(mysql));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_rpl_probe(object link)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
2003-02-15 02:35:30 +08:00
|
|
|
PHP_FUNCTION(mysqli_rpl_probe)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
if (mysql_rpl_probe(mysql)) {
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
2003-02-15 00:49:09 +08:00
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int mysqli_rpl_query_type(string query)
|
|
|
|
*/
|
2003-02-15 02:35:30 +08:00
|
|
|
PHP_FUNCTION(mysqli_rpl_query_type)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
char *query;
|
|
|
|
int query_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_rpl_query_type(query, query_len));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_send_long_data(object stmt, int param_nr, string data)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_send_long_data)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
2003-02-12 08:45:53 +08:00
|
|
|
char *data;
|
|
|
|
long param_nr, data_len;
|
|
|
|
|
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols", &mysql_stmt, mysqli_stmt_class_entry, ¶m_nr, &data, &data_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2004-01-26 15:39:57 +08:00
|
|
|
if (param_nr < 0) {
|
2003-02-12 08:45:53 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter number");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mysql_send_long_data(stmt->stmt, param_nr, data, data_len)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_send_query(object link, string query)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
2003-02-15 02:35:30 +08:00
|
|
|
PHP_FUNCTION(mysqli_send_query)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
char *query = NULL;
|
|
|
|
unsigned int query_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (mysql_send_query(mysql, query, query_len)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-10-30 04:48:47 +08:00
|
|
|
#ifdef HAVE_EMBEDDED_MYSQLI
|
|
|
|
/* {{{ proto bool mysqli_server_init(void)
|
2003-12-13 08:28:21 +08:00
|
|
|
initialize embedded server */
|
2003-10-30 04:48:47 +08:00
|
|
|
PHP_FUNCTION(mysqli_server_init)
|
|
|
|
{
|
|
|
|
zval *server;
|
|
|
|
zval *groups;
|
|
|
|
|
|
|
|
if (MyG(embedded)) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Embedded server already initialized.");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|aa", &server, &groups) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mysql_server_init(0, NULL, NULL)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
MyG(embedded) = 1;
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void mysqli_server_end(void)
|
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_server_end)
|
|
|
|
{
|
|
|
|
mysql_server_end();
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_slave_query(object link, string query)
|
2003-03-16 06:51:49 +08:00
|
|
|
Enforce execution of a query on a slave in a master/slave setup */
|
2003-02-15 02:35:30 +08:00
|
|
|
PHP_FUNCTION(mysqli_slave_query)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
char *query = NULL;
|
|
|
|
unsigned int query_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (mysql_slave_query(mysql, query, query_len)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto mixed mysqli_stmt_affected_rows(object stmt)
|
2003-05-04 11:15:02 +08:00
|
|
|
Return the number of rows affected in the last query for the given link */
|
2003-02-16 20:03:37 +08:00
|
|
|
PHP_FUNCTION(mysqli_stmt_affected_rows)
|
|
|
|
{
|
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
2003-03-09 07:33:12 +08:00
|
|
|
my_ulonglong rc;
|
2003-02-16 20:03:37 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-16 20:03:37 +08:00
|
|
|
|
|
|
|
rc = mysql_stmt_affected_rows(stmt->stmt);
|
2003-02-16 23:56:57 +08:00
|
|
|
MYSQLI_RETURN_LONG_LONG(rc)
|
2003-02-16 20:03:37 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto bool mysqli_stmt_close(object stmt)
|
2003-03-16 06:51:49 +08:00
|
|
|
Close statement */
|
2003-02-16 20:03:37 +08:00
|
|
|
PHP_FUNCTION(mysqli_stmt_close)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-18 08:00:51 +08:00
|
|
|
mysql_stmt_close(stmt->stmt);
|
2003-02-22 15:31:01 +08:00
|
|
|
stmt->stmt = NULL;
|
2003-02-12 08:45:53 +08:00
|
|
|
php_clear_stmt_bind(stmt);
|
|
|
|
MYSQLI_CLEAR_RESOURCE(&mysql_stmt);
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-07-15 22:00:19 +08:00
|
|
|
/* {{{ proto void mysqli_stmt_data_seek(object stmt, int offset)
|
2003-07-28 18:23:36 +08:00
|
|
|
Move internal result pointer */
|
2003-07-15 22:00:19 +08:00
|
|
|
PHP_FUNCTION(mysqli_stmt_data_seek)
|
|
|
|
{
|
2003-07-28 18:23:36 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
|
|
|
long offset;
|
2003-07-15 22:00:19 +08:00
|
|
|
|
2003-07-28 18:23:36 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_stmt, mysqli_stmt_class_entry, &offset) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-07-15 22:00:19 +08:00
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-07-15 22:00:19 +08:00
|
|
|
|
2003-08-31 19:03:05 +08:00
|
|
|
mysql_stmt_data_seek(stmt->stmt, offset);
|
2003-07-28 18:23:36 +08:00
|
|
|
return;
|
2003-07-15 22:00:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 16:46:39 +08:00
|
|
|
/* {{{ proto mixed mysqli_stmt_num_rows(object stmt)
|
|
|
|
Return the number of rows in statements result set */
|
|
|
|
PHP_FUNCTION(mysqli_stmt_num_rows)
|
|
|
|
{
|
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
|
|
|
my_ulonglong rc;
|
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-07-28 18:23:36 +08:00
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-06-22 16:46:39 +08:00
|
|
|
|
2003-08-31 19:03:05 +08:00
|
|
|
rc = mysql_stmt_num_rows(stmt->stmt);
|
2003-06-22 16:46:39 +08:00
|
|
|
MYSQLI_RETURN_LONG_LONG(rc)
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_select_db(object link, string dbname)
|
2003-03-16 06:51:49 +08:00
|
|
|
Select a MySQL database */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_select_db)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
char *dbname;
|
|
|
|
int dbname_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-06-29 05:27:08 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &dbname, &dbname_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (!mysql_select_db(mysql, dbname)) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_sqlstate(object link)
|
2003-06-21 21:35:26 +08:00
|
|
|
Returns the SQLSTATE error from previous MySQL operation */
|
|
|
|
#if MYSQL_VERSION_ID >= 40101
|
|
|
|
PHP_FUNCTION(mysqli_sqlstate)
|
|
|
|
{
|
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-06-21 21:35:26 +08:00
|
|
|
RETURN_STRING((char *)mysql_sqlstate(mysql),1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* }}} */
|
|
|
|
|
2003-11-30 18:56:55 +08:00
|
|
|
/* {{{ proto bool mysqli_ssl_set(object link ,string key ,string cert ,string ca ,string capath ,string cipher])
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_ssl_set)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
|
|
|
char *key=NULL, *cert=NULL, *ca=NULL, *capath=NULL, *cipher=NULL;
|
|
|
|
int key_len, cert_len, ca_len, capath_len, cipher_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osssss", &mysql_link, mysqli_link_class_entry,
|
|
|
|
&key, &key_len, &cert, &cert_len, &ca, &ca_len, &capath, &capath_len, &cipher, &cipher_len) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
mysql_ssl_set(mysql, key, cert, ca, capath, cipher);
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-26 21:38:13 +08:00
|
|
|
/* {{{ proto mixed mysqli_stat(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Get current system status */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_stat)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2004-01-26 21:38:13 +08:00
|
|
|
char *stat;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2004-01-27 04:08:16 +08:00
|
|
|
if ((stat = (char *)mysql_stat(mysql))) {
|
2004-01-26 21:38:13 +08:00
|
|
|
RETURN_STRING(stat, 1);
|
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_stmt_errno(object stmt)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_stmt_errno)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_stmt_errno(stmt->stmt));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto string mysqli_stmt_error(object stmt)
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_stmt_error)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_STRING((char *)mysql_stmt_error(stmt->stmt),1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-26 21:38:13 +08:00
|
|
|
/* {{{ proto bool mysqli_stmt_store_result(stmt)
|
2003-02-18 16:49:00 +08:00
|
|
|
*/
|
|
|
|
PHP_FUNCTION(mysqli_stmt_store_result)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
2003-02-18 16:49:00 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-02-18 16:49:00 +08:00
|
|
|
|
|
|
|
if (mysql_stmt_store_result(stmt->stmt)){
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
|
2003-02-18 16:49:00 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2003-03-09 07:33:12 +08:00
|
|
|
|
2003-09-17 03:45:22 +08:00
|
|
|
/* {{{ proto string mysqli_stmt_sqlstate(object stmt)
|
2003-06-21 21:35:26 +08:00
|
|
|
*/
|
|
|
|
#if MYSQL_VERSION_ID >= 40101
|
|
|
|
PHP_FUNCTION(mysqli_stmt_sqlstate)
|
|
|
|
{
|
|
|
|
STMT *stmt;
|
|
|
|
zval *mysql_stmt;
|
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
|
2003-06-21 21:35:26 +08:00
|
|
|
|
|
|
|
RETURN_STRING((char *)mysql_stmt_sqlstate(stmt->stmt),1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* }}} */
|
|
|
|
|
2003-10-30 04:48:47 +08:00
|
|
|
/* {{{ proto object mysqli_store_result(object link)
|
2003-05-04 11:15:02 +08:00
|
|
|
Buffer result set on client */
|
2003-03-09 07:33:12 +08:00
|
|
|
PHP_FUNCTION(mysqli_store_result)
|
|
|
|
{
|
|
|
|
MYSQL *mysql;
|
|
|
|
MYSQL_RES *result;
|
|
|
|
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;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-03-09 07:33:12 +08:00
|
|
|
|
|
|
|
if (!(result = mysql_store_result(mysql))) {
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
MYSQLI_DISABLE_MQ;
|
2003-03-09 07:33:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
|
2003-12-13 21:44:56 +08:00
|
|
|
php_mysqli_report_index("from previous mysql_real_connect", mysql->server_status TSRMLS_CC);
|
2003-12-13 08:28:21 +08:00
|
|
|
}
|
|
|
|
MYSQLI_DISABLE_MQ;
|
2003-03-09 07:33:12 +08:00
|
|
|
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
|
|
|
|
mysqli_resource->ptr = (void *)result;
|
|
|
|
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-06-22 14:16:47 +08:00
|
|
|
/* {{{ proto int mysqli_thread_id(object link)
|
2003-03-16 06:51:49 +08:00
|
|
|
Return the current thread ID */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_thread_id)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_thread_id(mysql));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool mysqli_thread_safe(void)
|
2003-03-16 06:51:49 +08:00
|
|
|
Return whether thread safety is given or not */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_thread_safe)
|
|
|
|
{
|
|
|
|
RETURN_BOOL(mysql_thread_safe());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2004-01-26 21:38:13 +08:00
|
|
|
/* {{{ proto mixed mysqli_use_result(object link)
|
2003-05-04 11:15:02 +08:00
|
|
|
Directly retrieve query results - do not buffer results on client side */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_use_result)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_link;
|
|
|
|
MYSQLI_RESOURCE *mysqli_resource;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
if (!(result = mysql_use_result(mysql))) {
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_REPORT_MYSQL_ERROR(mysql);
|
|
|
|
MYSQLI_DISABLE_MQ;
|
2003-02-12 08:45:53 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
|
|
|
|
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
|
2003-12-13 21:44:56 +08:00
|
|
|
php_mysqli_report_index("from previous mysql_real_connect", mysql->server_status TSRMLS_CC);
|
2003-12-13 08:28:21 +08:00
|
|
|
}
|
|
|
|
|
2003-03-09 07:33:12 +08:00
|
|
|
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
|
|
|
|
mysqli_resource->ptr = (void *)result;
|
|
|
|
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-10-30 04:48:47 +08:00
|
|
|
/* {{{ proto int mysqli_warning_count (object link)
|
2003-05-04 11:15:02 +08:00
|
|
|
Return number of warnings from the last query for the given link */
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_FUNCTION(mysqli_warning_count)
|
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL *mysql;
|
|
|
|
zval *mysql_link;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
RETURN_LONG(mysql_warning_count(mysql));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|