php-src/ext/mysqli/mysqli_api.c

1926 lines
52 KiB
C
Raw Normal View History

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