2004-05-19 02:01:52 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP Version 5 |
|
|
|
|
+----------------------------------------------------------------------+
|
2013-01-01 16:28:54 +08:00
|
|
|
| Copyright (c) 1997-2013 The PHP Group |
|
2004-05-19 02:01:52 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2004-05-19 02:01:52 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2004-05-19 02:01:52 +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: George Schlossnagle <george@omniti.com> |
|
2005-07-03 10:20:08 +08:00
|
|
|
| Wez Furlong <wez@php.net> |
|
2008-07-21 21:09:28 +08:00
|
|
|
| Johannes Schlueter <johannes@mysql.com> |
|
2004-05-19 02:01:52 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "ext/standard/info.h"
|
|
|
|
#include "pdo/php_pdo.h"
|
|
|
|
#include "pdo/php_pdo_driver.h"
|
|
|
|
#include "php_pdo_mysql.h"
|
|
|
|
#include "php_pdo_mysql_int.h"
|
2008-07-21 21:09:28 +08:00
|
|
|
#ifndef PDO_USE_MYSQLND
|
2005-02-27 19:39:15 +08:00
|
|
|
#include <mysqld_error.h>
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
2004-07-28 08:03:44 +08:00
|
|
|
#include "zend_exceptions.h"
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2011-09-02 21:53:41 +08:00
|
|
|
#if defined(PDO_USE_MYSQLND)
|
2008-07-21 21:09:28 +08:00
|
|
|
# define pdo_mysql_init(persistent) mysqlnd_init(persistent)
|
|
|
|
#else
|
|
|
|
# define pdo_mysql_init(persistent) mysql_init(NULL)
|
|
|
|
#endif
|
2005-02-27 19:39:15 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ _pdo_mysql_error */
|
2011-09-19 20:31:06 +08:00
|
|
|
int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC)
|
2004-05-19 02:01:52 +08:00
|
|
|
{
|
2004-05-20 23:51:25 +08:00
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
2005-02-28 04:34:36 +08:00
|
|
|
pdo_error_type *pdo_err;
|
|
|
|
pdo_mysql_error_info *einfo;
|
2005-07-03 10:20:08 +08:00
|
|
|
pdo_mysql_stmt *S = NULL;
|
2004-05-20 23:51:25 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("_pdo_mysql_error");
|
|
|
|
PDO_DBG_INF_FMT("file=%s line=%d", file, line);
|
2005-02-28 04:34:36 +08:00
|
|
|
if (stmt) {
|
2005-07-03 10:20:08 +08:00
|
|
|
S = (pdo_mysql_stmt*)stmt->driver_data;
|
2005-02-28 04:34:36 +08:00
|
|
|
pdo_err = &stmt->error_code;
|
|
|
|
einfo = &S->einfo;
|
|
|
|
} else {
|
|
|
|
pdo_err = &dbh->error_code;
|
|
|
|
einfo = &H->einfo;
|
|
|
|
}
|
|
|
|
|
2005-10-29 10:36:30 +08:00
|
|
|
if (S && S->stmt) {
|
|
|
|
einfo->errcode = mysql_stmt_errno(S->stmt);
|
2010-08-05 21:29:44 +08:00
|
|
|
} else {
|
2005-10-29 10:36:30 +08:00
|
|
|
einfo->errcode = mysql_errno(H->server);
|
|
|
|
}
|
|
|
|
|
2004-05-20 23:51:25 +08:00
|
|
|
einfo->file = file;
|
|
|
|
einfo->line = line;
|
|
|
|
|
|
|
|
if (einfo->errmsg) {
|
2004-09-24 05:03:41 +08:00
|
|
|
pefree(einfo->errmsg, dbh->is_persistent);
|
2004-05-20 23:51:25 +08:00
|
|
|
einfo->errmsg = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (einfo->errcode) {
|
2008-07-21 21:09:28 +08:00
|
|
|
if (einfo->errcode == 2014) {
|
2005-07-03 10:20:08 +08:00
|
|
|
einfo->errmsg = pestrdup(
|
|
|
|
"Cannot execute queries while other unbuffered queries are active. "
|
|
|
|
"Consider using PDOStatement::fetchAll(). Alternatively, if your code "
|
|
|
|
"is only ever going to run against mysql, you may enable query "
|
2005-10-06 06:14:52 +08:00
|
|
|
"buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.",
|
2005-07-03 10:20:08 +08:00
|
|
|
dbh->is_persistent);
|
2008-07-21 21:09:28 +08:00
|
|
|
} else if (einfo->errcode == 2057) {
|
|
|
|
einfo->errmsg = pestrdup(
|
|
|
|
"A stored procedure returning result sets of different size was called. "
|
|
|
|
"This is not supported by libmysql",
|
|
|
|
dbh->is_persistent);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent);
|
2005-06-25 03:45:59 +08:00
|
|
|
}
|
2004-05-20 23:51:25 +08:00
|
|
|
} else { /* no error */
|
2005-01-07 13:24:21 +08:00
|
|
|
strcpy(*pdo_err, PDO_ERR_NONE);
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(0);
|
2004-05-20 23:51:25 +08:00
|
|
|
}
|
|
|
|
|
2005-07-03 10:20:08 +08:00
|
|
|
if (S && S->stmt) {
|
|
|
|
strcpy(*pdo_err, mysql_stmt_sqlstate(S->stmt));
|
2010-08-05 21:29:44 +08:00
|
|
|
} else {
|
2005-07-03 10:20:08 +08:00
|
|
|
strcpy(*pdo_err, mysql_sqlstate(H->server));
|
|
|
|
}
|
2005-02-28 04:34:36 +08:00
|
|
|
|
2004-05-25 20:03:41 +08:00
|
|
|
if (!dbh->methods) {
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_INF("Throwing exception");
|
2010-01-12 20:46:54 +08:00
|
|
|
zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
|
2005-01-07 13:24:21 +08:00
|
|
|
*pdo_err, einfo->errcode, einfo->errmsg);
|
2004-05-25 20:03:41 +08:00
|
|
|
}
|
2005-02-27 19:39:15 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(einfo->errcode);
|
2004-05-19 02:01:52 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ pdo_mysql_fetch_error_func */
|
2004-05-20 23:51:25 +08:00
|
|
|
static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC)
|
2004-05-19 02:01:52 +08:00
|
|
|
{
|
2004-05-20 23:51:25 +08:00
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
|
|
|
pdo_mysql_error_info *einfo = &H->einfo;
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("pdo_mysql_fetch_error_func");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p stmt=%p", dbh, stmt);
|
2005-02-28 04:34:36 +08:00
|
|
|
if (stmt) {
|
|
|
|
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
|
|
|
|
einfo = &S->einfo;
|
|
|
|
} else {
|
|
|
|
einfo = &H->einfo;
|
|
|
|
}
|
|
|
|
|
2004-05-20 23:51:25 +08:00
|
|
|
if (einfo->errcode) {
|
|
|
|
add_next_index_long(info, einfo->errcode);
|
|
|
|
add_next_index_string(info, einfo->errmsg, 1);
|
|
|
|
}
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(1);
|
2004-05-19 02:01:52 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_handle_closer */
|
2011-09-19 20:31:06 +08:00
|
|
|
static int mysql_handle_closer(pdo_dbh_t *dbh TSRMLS_DC)
|
2004-05-19 02:01:52 +08:00
|
|
|
{
|
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
2004-05-25 22:39:26 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("mysql_handle_closer");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
2004-05-25 22:39:26 +08:00
|
|
|
if (H) {
|
|
|
|
if (H->server) {
|
|
|
|
mysql_close(H->server);
|
|
|
|
H->server = NULL;
|
|
|
|
}
|
|
|
|
if (H->einfo.errmsg) {
|
2004-09-24 05:03:41 +08:00
|
|
|
pefree(H->einfo.errmsg, dbh->is_persistent);
|
2004-05-25 22:39:26 +08:00
|
|
|
H->einfo.errmsg = NULL;
|
|
|
|
}
|
2004-09-24 04:43:11 +08:00
|
|
|
pefree(H, dbh->is_persistent);
|
2004-07-28 08:40:01 +08:00
|
|
|
dbh->driver_data = NULL;
|
2004-05-20 01:35:39 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(0);
|
2004-05-19 02:01:52 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_handle_preparer */
|
2005-01-21 08:39:03 +08:00
|
|
|
static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC)
|
2004-05-19 02:01:52 +08:00
|
|
|
{
|
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
|
|
|
pdo_mysql_stmt *S = ecalloc(1, sizeof(pdo_mysql_stmt));
|
2005-07-03 10:20:08 +08:00
|
|
|
char *nsql = NULL;
|
|
|
|
int nsql_len = 0;
|
|
|
|
int ret;
|
2006-04-09 16:11:31 +08:00
|
|
|
int server_version;
|
2005-07-03 10:20:08 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("mysql_handle_preparer");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
PDO_DBG_INF_FMT("sql=%.*s", sql_len, sql);
|
|
|
|
|
2004-05-19 02:01:52 +08:00
|
|
|
S->H = H;
|
|
|
|
stmt->driver_data = S;
|
|
|
|
stmt->methods = &mysql_stmt_methods;
|
2005-07-03 10:20:08 +08:00
|
|
|
|
2006-03-06 01:18:01 +08:00
|
|
|
if (H->emulate_prepare) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2006-04-09 16:11:31 +08:00
|
|
|
server_version = mysql_get_server_version(H->server);
|
|
|
|
if (server_version < 40100) {
|
|
|
|
goto fallback;
|
|
|
|
}
|
2005-07-03 10:20:08 +08:00
|
|
|
stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
|
|
|
|
ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len TSRMLS_CC);
|
|
|
|
|
|
|
|
if (ret == 1) {
|
|
|
|
/* query was rewritten */
|
|
|
|
sql = nsql;
|
|
|
|
sql_len = nsql_len;
|
|
|
|
} else if (ret == -1) {
|
|
|
|
/* failed to parse */
|
|
|
|
strcpy(dbh->error_code, stmt->error_code);
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(0);
|
2005-07-03 10:20:08 +08:00
|
|
|
}
|
|
|
|
|
2005-07-13 03:32:13 +08:00
|
|
|
if (!(S->stmt = mysql_stmt_init(H->server))) {
|
2005-07-03 10:20:08 +08:00
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
if (nsql) {
|
|
|
|
efree(nsql);
|
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(0);
|
2005-07-03 10:20:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mysql_stmt_prepare(S->stmt, sql, sql_len)) {
|
|
|
|
/* TODO: might need to pull statement specific info here? */
|
2005-08-31 12:06:10 +08:00
|
|
|
/* if the query isn't supported by the protocol, fallback to emulation */
|
|
|
|
if (mysql_errno(H->server) == 1295) {
|
|
|
|
if (nsql) {
|
|
|
|
efree(nsql);
|
|
|
|
}
|
|
|
|
goto fallback;
|
|
|
|
}
|
2005-07-03 10:20:08 +08:00
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
if (nsql) {
|
|
|
|
efree(nsql);
|
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(0);
|
2005-07-03 10:20:08 +08:00
|
|
|
}
|
2005-07-08 00:27:46 +08:00
|
|
|
if (nsql) {
|
|
|
|
efree(nsql);
|
|
|
|
}
|
2005-07-03 10:20:08 +08:00
|
|
|
|
|
|
|
S->num_params = mysql_stmt_param_count(S->stmt);
|
|
|
|
|
|
|
|
if (S->num_params) {
|
2008-07-21 21:09:28 +08:00
|
|
|
S->params_given = 0;
|
2011-09-02 21:53:41 +08:00
|
|
|
#if defined(PDO_USE_MYSQLND)
|
2008-07-21 21:09:28 +08:00
|
|
|
S->params = NULL;
|
|
|
|
#else
|
2005-07-03 10:20:08 +08:00
|
|
|
S->params = ecalloc(S->num_params, sizeof(MYSQL_BIND));
|
|
|
|
S->in_null = ecalloc(S->num_params, sizeof(my_bool));
|
|
|
|
S->in_length = ecalloc(S->num_params, sizeof(unsigned long));
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
2005-07-03 10:20:08 +08:00
|
|
|
}
|
|
|
|
dbh->alloc_own_columns = 1;
|
|
|
|
|
2005-07-20 11:38:33 +08:00
|
|
|
S->max_length = pdo_attr_lval(driver_options, PDO_ATTR_MAX_COLUMN_LEN, 0 TSRMLS_CC);
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(1);
|
2005-07-03 10:20:08 +08:00
|
|
|
|
2005-08-31 12:06:10 +08:00
|
|
|
fallback:
|
2006-03-06 01:18:01 +08:00
|
|
|
end:
|
2005-08-31 12:06:10 +08:00
|
|
|
stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(1);
|
2004-05-19 02:01:52 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_handle_doer */
|
2004-05-20 03:31:33 +08:00
|
|
|
static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC)
|
2004-05-19 02:01:52 +08:00
|
|
|
{
|
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("mysql_handle_doer");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
PDO_DBG_INF_FMT("sql=%.*s", sql_len, sql);
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2004-05-20 01:35:39 +08:00
|
|
|
if (mysql_real_query(H->server, sql, sql_len)) {
|
2004-05-20 23:51:25 +08:00
|
|
|
pdo_mysql_error(dbh);
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(-1);
|
2004-05-20 01:35:39 +08:00
|
|
|
} else {
|
2005-09-14 23:34:58 +08:00
|
|
|
my_ulonglong c = mysql_affected_rows(H->server);
|
2005-11-25 20:56:04 +08:00
|
|
|
if (c == (my_ulonglong) -1) {
|
2005-09-14 23:34:58 +08:00
|
|
|
pdo_mysql_error(dbh);
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(H->einfo.errcode ? -1 : 0);
|
2005-09-14 23:34:58 +08:00
|
|
|
} else {
|
2008-07-21 21:09:28 +08:00
|
|
|
|
|
|
|
/* MULTI_QUERY support - eat up all unfetched result sets */
|
|
|
|
MYSQL_RES* result;
|
|
|
|
while (mysql_more_results(H->server)) {
|
|
|
|
if (mysql_next_result(H->server)) {
|
|
|
|
PDO_DBG_RETURN(1);
|
|
|
|
}
|
|
|
|
result = mysql_store_result(H->server);
|
|
|
|
if (result) {
|
|
|
|
mysql_free_result(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PDO_DBG_RETURN((int)c);
|
2005-09-14 23:34:58 +08:00
|
|
|
}
|
2004-05-20 01:35:39 +08:00
|
|
|
}
|
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2004-05-20 01:35:39 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ pdo_mysql_last_insert_id */
|
2005-02-27 09:30:58 +08:00
|
|
|
static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned int *len TSRMLS_DC)
|
2004-05-20 01:35:39 +08:00
|
|
|
{
|
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
2005-07-09 03:25:37 +08:00
|
|
|
char *id = php_pdo_int64_to_str(mysql_insert_id(H->server) TSRMLS_CC);
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("pdo_mysql_last_insert_id");
|
2005-07-09 03:25:37 +08:00
|
|
|
*len = strlen(id);
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(id);
|
2004-05-19 02:01:52 +08:00
|
|
|
}
|
2011-09-19 20:31:06 +08:00
|
|
|
/* }}} */
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_handle_quoter */
|
2005-02-07 07:22:37 +08:00
|
|
|
static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC)
|
2004-05-19 02:01:52 +08:00
|
|
|
{
|
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("mysql_handle_quoter");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
PDO_DBG_INF_FMT("unquoted=%.*s", unquotedlen, unquoted);
|
2005-07-11 22:46:01 +08:00
|
|
|
*quoted = safe_emalloc(2, unquotedlen, 3);
|
2004-05-19 23:12:05 +08:00
|
|
|
*quotedlen = mysql_real_escape_string(H->server, *quoted + 1, unquoted, unquotedlen);
|
2005-12-26 04:30:40 +08:00
|
|
|
(*quoted)[0] =(*quoted)[++*quotedlen] = '\'';
|
2005-07-11 22:46:01 +08:00
|
|
|
(*quoted)[++*quotedlen] = '\0';
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_INF_FMT("quoted=%.*s", *quotedlen, *quoted);
|
|
|
|
PDO_DBG_RETURN(1);
|
2004-05-19 02:01:52 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_handle_begin */
|
2005-02-13 08:51:17 +08:00
|
|
|
static int mysql_handle_begin(pdo_dbh_t *dbh TSRMLS_DC)
|
|
|
|
{
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("mysql_handle_quoter");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("START TRANSACTION") TSRMLS_CC));
|
2005-02-13 08:51:17 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2005-02-13 08:51:17 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_handle_commit */
|
2005-02-13 08:51:17 +08:00
|
|
|
static int mysql_handle_commit(pdo_dbh_t *dbh TSRMLS_DC)
|
|
|
|
{
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("mysql_handle_commit");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
#if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND)
|
|
|
|
PDO_DBG_RETURN(0 <= mysql_commit(((pdo_mysql_db_handle *)dbh->driver_data)->server));
|
|
|
|
#else
|
|
|
|
PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("COMMIT") TSRMLS_CC));
|
|
|
|
#endif
|
2005-02-13 08:51:17 +08:00
|
|
|
}
|
2011-09-19 20:31:06 +08:00
|
|
|
/* }}} */
|
2005-02-13 08:51:17 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_handle_rollback */
|
2005-02-13 08:51:17 +08:00
|
|
|
static int mysql_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC)
|
|
|
|
{
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("mysql_handle_rollback");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
#if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND)
|
|
|
|
PDO_DBG_RETURN(0 <= mysql_rollback(((pdo_mysql_db_handle *)dbh->driver_data)->server));
|
|
|
|
#else
|
|
|
|
PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("ROLLBACK") TSRMLS_CC));
|
|
|
|
#endif
|
2005-02-13 08:51:17 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2005-02-13 08:51:17 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_handle_autocommit */
|
|
|
|
static inline int mysql_handle_autocommit(pdo_dbh_t *dbh TSRMLS_DC)
|
2005-02-13 08:51:17 +08:00
|
|
|
{
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("mysql_handle_autocommit");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
PDO_DBG_INF_FMT("dbh->autocommit=%d", dbh->auto_commit);
|
|
|
|
#if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND)
|
|
|
|
PDO_DBG_RETURN(0 <= mysql_autocommit(((pdo_mysql_db_handle *)dbh->driver_data)->server, dbh->auto_commit));
|
|
|
|
#else
|
2005-02-13 08:55:16 +08:00
|
|
|
if (dbh->auto_commit) {
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=1") TSRMLS_CC));
|
2005-02-13 08:55:16 +08:00
|
|
|
} else {
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=0") TSRMLS_CC));
|
2005-02-13 08:55:16 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
2005-02-13 08:51:17 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2005-02-13 08:51:17 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ pdo_mysql_set_attribute */
|
2005-02-13 08:51:17 +08:00
|
|
|
static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC)
|
|
|
|
{
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("pdo_mysql_set_attribute");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
PDO_DBG_INF_FMT("attr=%l", attr);
|
2005-02-13 08:51:17 +08:00
|
|
|
switch (attr) {
|
2008-07-21 21:09:28 +08:00
|
|
|
case PDO_ATTR_AUTOCOMMIT:
|
|
|
|
convert_to_boolean(val);
|
2005-02-13 08:51:17 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* ignore if the new value equals the old one */
|
|
|
|
if (dbh->auto_commit ^ Z_BVAL_P(val)) {
|
|
|
|
dbh->auto_commit = Z_BVAL_P(val);
|
|
|
|
mysql_handle_autocommit(dbh TSRMLS_CC);
|
|
|
|
}
|
|
|
|
PDO_DBG_RETURN(1);
|
|
|
|
|
|
|
|
case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY:
|
|
|
|
((pdo_mysql_db_handle *)dbh->driver_data)->buffered = Z_BVAL_P(val);
|
|
|
|
PDO_DBG_RETURN(1);
|
|
|
|
case PDO_MYSQL_ATTR_DIRECT_QUERY:
|
|
|
|
case PDO_ATTR_EMULATE_PREPARES:
|
|
|
|
((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = Z_BVAL_P(val);
|
|
|
|
PDO_DBG_RETURN(1);
|
|
|
|
case PDO_ATTR_FETCH_TABLE_NAMES:
|
|
|
|
((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = Z_BVAL_P(val);
|
|
|
|
PDO_DBG_RETURN(1);
|
|
|
|
#ifndef PDO_USE_MYSQLND
|
|
|
|
case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE:
|
|
|
|
if (Z_LVAL_P(val) < 0) {
|
2008-08-03 20:15:55 +08:00
|
|
|
/* TODO: Johannes, can we throw a warning here? */
|
2008-07-21 21:09:28 +08:00
|
|
|
((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = 1024*1024;
|
|
|
|
PDO_DBG_INF_FMT("Adjusting invalid buffer size to =%l", ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size);
|
|
|
|
} else {
|
|
|
|
((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = Z_LVAL_P(val);
|
|
|
|
}
|
|
|
|
PDO_DBG_RETURN(1);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
PDO_DBG_RETURN(0);
|
2005-02-13 08:51:17 +08:00
|
|
|
}
|
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2005-02-13 08:51:17 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ pdo_mysql_get_attribute */
|
2004-05-21 03:17:32 +08:00
|
|
|
static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value TSRMLS_DC)
|
|
|
|
{
|
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("pdo_mysql_get_attribute");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
PDO_DBG_INF_FMT("attr=%l", attr);
|
2004-05-21 03:17:32 +08:00
|
|
|
switch (attr) {
|
|
|
|
case PDO_ATTR_CLIENT_VERSION:
|
|
|
|
ZVAL_STRING(return_value, (char *)mysql_get_client_info(), 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PDO_ATTR_SERVER_VERSION:
|
|
|
|
ZVAL_STRING(return_value, (char *)mysql_get_server_info(H->server), 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PDO_ATTR_CONNECTION_STATUS:
|
|
|
|
ZVAL_STRING(return_value, (char *)mysql_get_host_info(H->server), 1);
|
|
|
|
break;
|
|
|
|
case PDO_ATTR_SERVER_INFO: {
|
|
|
|
char *tmp;
|
2011-09-02 21:53:41 +08:00
|
|
|
#if defined(PDO_USE_MYSQLND)
|
2010-02-04 01:31:29 +08:00
|
|
|
unsigned int tmp_len;
|
2004-05-21 03:17:32 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
if (mysqlnd_stat(H->server, &tmp, &tmp_len) == PASS) {
|
|
|
|
ZVAL_STRINGL(return_value, tmp, tmp_len, 0);
|
|
|
|
#else
|
2004-05-21 03:17:32 +08:00
|
|
|
if ((tmp = (char *)mysql_stat(H->server))) {
|
|
|
|
ZVAL_STRING(return_value, tmp, 1);
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
2004-05-21 03:17:32 +08:00
|
|
|
} else {
|
|
|
|
pdo_mysql_error(dbh);
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(-1);
|
2004-05-21 03:17:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-02-13 08:51:17 +08:00
|
|
|
case PDO_ATTR_AUTOCOMMIT:
|
|
|
|
ZVAL_LONG(return_value, dbh->auto_commit);
|
2008-07-21 21:09:28 +08:00
|
|
|
break;
|
2005-07-11 21:52:13 +08:00
|
|
|
|
2005-06-25 03:45:59 +08:00
|
|
|
case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY:
|
|
|
|
ZVAL_LONG(return_value, H->buffered);
|
2008-07-21 21:09:28 +08:00
|
|
|
break;
|
2005-06-25 03:45:59 +08:00
|
|
|
|
2006-03-17 08:15:09 +08:00
|
|
|
case PDO_MYSQL_ATTR_DIRECT_QUERY:
|
|
|
|
ZVAL_LONG(return_value, H->emulate_prepare);
|
2008-07-21 21:09:28 +08:00
|
|
|
break;
|
2006-03-17 08:15:09 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
#ifndef PDO_USE_MYSQLND
|
2006-03-17 08:15:09 +08:00
|
|
|
case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE:
|
|
|
|
ZVAL_LONG(return_value, H->max_buffer_size);
|
2008-07-21 21:09:28 +08:00
|
|
|
break;
|
|
|
|
#endif
|
2006-03-17 08:15:09 +08:00
|
|
|
|
2004-05-21 03:17:32 +08:00
|
|
|
default:
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(0);
|
2004-05-21 03:17:32 +08:00
|
|
|
}
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(1);
|
2004-05-21 03:17:32 +08:00
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ pdo_mysql_check_liveness */
|
2011-09-19 20:31:06 +08:00
|
|
|
static int pdo_mysql_check_liveness(pdo_dbh_t *dbh TSRMLS_DC)
|
2006-10-03 06:09:49 +08:00
|
|
|
{
|
|
|
|
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
|
|
|
|
#if MYSQL_VERSION_ID <= 32230
|
|
|
|
void (*handler) (int);
|
|
|
|
unsigned int my_errno;
|
|
|
|
#endif
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_ENTER("pdo_mysql_check_liveness");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
|
2006-10-03 06:09:49 +08:00
|
|
|
#if MYSQL_VERSION_ID > 32230
|
|
|
|
if (mysql_ping(H->server)) {
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(FAILURE);
|
2006-10-03 06:09:49 +08:00
|
|
|
}
|
|
|
|
#else /* no mysql_ping() */
|
2008-07-21 21:09:28 +08:00
|
|
|
handler = signal(SIGPIPE, SIG_IGN);
|
2006-10-03 06:09:49 +08:00
|
|
|
mysql_stat(H->server);
|
|
|
|
switch (mysql_errno(H->server)) {
|
|
|
|
case CR_SERVER_GONE_ERROR:
|
2008-07-21 21:09:28 +08:00
|
|
|
case CR_SERVER_LOST:
|
2006-10-03 06:09:49 +08:00
|
|
|
signal(SIGPIPE, handler);
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(FAILURE);
|
2006-10-03 06:09:49 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
signal(SIGPIPE, handler);
|
|
|
|
#endif /* end mysql_ping() */
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(SUCCESS);
|
2006-10-03 06:09:49 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2005-02-13 08:51:17 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ mysql_methods */
|
2004-05-19 02:01:52 +08:00
|
|
|
static struct pdo_dbh_methods mysql_methods = {
|
|
|
|
mysql_handle_closer,
|
|
|
|
mysql_handle_preparer,
|
|
|
|
mysql_handle_doer,
|
2004-05-20 01:35:39 +08:00
|
|
|
mysql_handle_quoter,
|
2005-02-13 08:51:17 +08:00
|
|
|
mysql_handle_begin,
|
|
|
|
mysql_handle_commit,
|
|
|
|
mysql_handle_rollback,
|
|
|
|
pdo_mysql_set_attribute,
|
2004-05-20 23:51:25 +08:00
|
|
|
pdo_mysql_last_insert_id,
|
2004-05-21 03:17:32 +08:00
|
|
|
pdo_mysql_fetch_error_func,
|
2004-09-24 04:20:23 +08:00
|
|
|
pdo_mysql_get_attribute,
|
2006-10-03 06:09:49 +08:00
|
|
|
pdo_mysql_check_liveness
|
2004-05-19 02:01:52 +08:00
|
|
|
};
|
2008-07-21 21:09:28 +08:00
|
|
|
/* }}} */
|
2011-11-02 23:45:53 +08:00
|
|
|
|
|
|
|
#ifdef PHP_WIN32
|
2013-07-23 18:50:37 +08:00
|
|
|
# define PDO_DEFAULT_MYSQL_UNIX_ADDR NULL
|
2011-11-02 23:45:53 +08:00
|
|
|
#else
|
2013-07-23 18:50:37 +08:00
|
|
|
# define PDO_DEFAULT_MYSQL_UNIX_ADDR PDO_MYSQL_G(default_socket)
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
2004-05-25 20:44:35 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
/* {{{ pdo_mysql_handle_factory */
|
2011-09-19 20:31:06 +08:00
|
|
|
static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC)
|
2004-05-19 02:01:52 +08:00
|
|
|
{
|
|
|
|
pdo_mysql_db_handle *H;
|
|
|
|
int i, ret = 0;
|
|
|
|
char *host = NULL, *unix_socket = NULL;
|
2005-02-13 04:58:29 +08:00
|
|
|
unsigned int port = 3306;
|
2004-05-19 02:01:52 +08:00
|
|
|
char *dbname;
|
|
|
|
struct pdo_data_src_parser vars[] = {
|
|
|
|
{ "charset", NULL, 0 },
|
|
|
|
{ "dbname", "", 0 },
|
|
|
|
{ "host", "localhost", 0 },
|
|
|
|
{ "port", "3306", 0 },
|
2013-07-23 18:50:37 +08:00
|
|
|
{ "unix_socket", PDO_DEFAULT_MYSQL_UNIX_ADDR, 0 },
|
2004-05-19 02:01:52 +08:00
|
|
|
};
|
2005-07-03 05:01:38 +08:00
|
|
|
int connect_opts = 0
|
|
|
|
#ifdef CLIENT_MULTI_RESULTS
|
|
|
|
|CLIENT_MULTI_RESULTS
|
|
|
|
#endif
|
|
|
|
#ifdef CLIENT_MULTI_STATEMENTS
|
|
|
|
|CLIENT_MULTI_STATEMENTS
|
|
|
|
#endif
|
|
|
|
;
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2011-09-02 21:53:41 +08:00
|
|
|
#if defined(PDO_USE_MYSQLND)
|
2008-07-21 21:09:28 +08:00
|
|
|
int dbname_len = 0;
|
|
|
|
int password_len = 0;
|
|
|
|
#endif
|
|
|
|
PDO_DBG_ENTER("pdo_mysql_handle_factory");
|
|
|
|
PDO_DBG_INF_FMT("dbh=%p", dbh);
|
|
|
|
#ifdef CLIENT_MULTI_RESULTS
|
|
|
|
PDO_DBG_INF("multi results");
|
|
|
|
#endif
|
|
|
|
|
2005-08-31 12:06:10 +08:00
|
|
|
php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 5);
|
2004-05-19 02:01:52 +08:00
|
|
|
|
|
|
|
H = pecalloc(1, sizeof(pdo_mysql_db_handle), dbh->is_persistent);
|
2008-07-21 21:09:28 +08:00
|
|
|
|
2004-05-20 23:51:25 +08:00
|
|
|
H->einfo.errcode = 0;
|
|
|
|
H->einfo.errmsg = NULL;
|
|
|
|
|
2004-05-19 02:01:52 +08:00
|
|
|
/* allocate an environment */
|
2006-12-04 07:29:03 +08:00
|
|
|
|
2004-05-19 02:01:52 +08:00
|
|
|
/* handle for the server */
|
2008-07-21 21:09:28 +08:00
|
|
|
if (!(H->server = pdo_mysql_init(dbh->is_persistent))) {
|
2005-07-11 21:52:13 +08:00
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2004-05-20 01:35:39 +08:00
|
|
|
dbh->driver_data = H;
|
2008-07-21 21:09:28 +08:00
|
|
|
|
|
|
|
#ifndef PDO_USE_MYSQLND
|
2006-03-23 09:24:36 +08:00
|
|
|
H->max_buffer_size = 1024*1024;
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
|
|
|
|
2006-12-09 03:50:40 +08:00
|
|
|
H->buffered = H->emulate_prepare = 1;
|
2004-05-20 04:34:57 +08:00
|
|
|
|
|
|
|
/* handle MySQL options */
|
|
|
|
if (driver_options) {
|
|
|
|
long connect_timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30 TSRMLS_CC);
|
2005-10-28 01:34:24 +08:00
|
|
|
long local_infile = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_LOCAL_INFILE, 0 TSRMLS_CC);
|
2009-09-22 23:31:35 +08:00
|
|
|
char *init_cmd = NULL;
|
2008-07-21 21:09:28 +08:00
|
|
|
#ifndef PDO_USE_MYSQLND
|
2009-09-22 23:31:35 +08:00
|
|
|
char *default_file = NULL, *default_group = NULL;
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
2012-03-06 07:57:24 +08:00
|
|
|
long compress = 0;
|
2011-04-15 22:24:40 +08:00
|
|
|
char *ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL, *ssl_cipher = NULL;
|
2006-12-04 07:29:03 +08:00
|
|
|
H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1 TSRMLS_CC);
|
2006-04-09 16:11:31 +08:00
|
|
|
|
|
|
|
H->emulate_prepare = pdo_attr_lval(driver_options,
|
|
|
|
PDO_MYSQL_ATTR_DIRECT_QUERY, H->emulate_prepare TSRMLS_CC);
|
|
|
|
H->emulate_prepare = pdo_attr_lval(driver_options,
|
|
|
|
PDO_ATTR_EMULATE_PREPARES, H->emulate_prepare TSRMLS_CC);
|
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
#ifndef PDO_USE_MYSQLND
|
2006-03-23 09:24:36 +08:00
|
|
|
H->max_buffer_size = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_MAX_BUFFER_SIZE, H->max_buffer_size TSRMLS_CC);
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
2006-02-14 22:26:11 +08:00
|
|
|
|
2008-10-28 02:32:08 +08:00
|
|
|
if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_FOUND_ROWS, 0 TSRMLS_CC)) {
|
|
|
|
connect_opts |= CLIENT_FOUND_ROWS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_IGNORE_SPACE, 0 TSRMLS_CC)) {
|
|
|
|
connect_opts |= CLIENT_IGNORE_SPACE;
|
|
|
|
}
|
|
|
|
|
2004-05-20 04:34:57 +08:00
|
|
|
if (mysql_options(H->server, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout)) {
|
2004-05-20 23:51:25 +08:00
|
|
|
pdo_mysql_error(dbh);
|
2004-05-20 04:34:57 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2007-06-19 05:51:32 +08:00
|
|
|
|
2010-04-27 07:53:30 +08:00
|
|
|
#if PHP_API_VERSION < 20100412
|
2008-07-21 21:09:28 +08:00
|
|
|
if ((PG(open_basedir) && PG(open_basedir)[0] != '\0') || PG(safe_mode))
|
|
|
|
#else
|
|
|
|
if (PG(open_basedir) && PG(open_basedir)[0] != '\0')
|
|
|
|
#endif
|
|
|
|
{
|
2007-06-19 05:51:32 +08:00
|
|
|
local_infile = 0;
|
|
|
|
}
|
2011-09-02 21:53:41 +08:00
|
|
|
#if defined(MYSQL_OPT_LOCAL_INFILE) || defined(PDO_USE_MYSQLND)
|
2005-10-28 01:34:24 +08:00
|
|
|
if (mysql_options(H->server, MYSQL_OPT_LOCAL_INFILE, (const char *)&local_infile)) {
|
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-12-31 03:11:13 +08:00
|
|
|
#endif
|
2006-04-09 16:11:31 +08:00
|
|
|
#ifdef MYSQL_OPT_RECONNECT
|
|
|
|
/* since 5.0.3, the default for this option is 0 if not specified.
|
2011-09-02 21:53:41 +08:00
|
|
|
* we want the old behaviour
|
|
|
|
* mysqlnd doesn't support reconnect, thus we don't have "|| defined(PDO_USE_MYSQLND)"
|
|
|
|
*/
|
2006-04-09 16:11:31 +08:00
|
|
|
{
|
|
|
|
long reconnect = 1;
|
|
|
|
mysql_options(H->server, MYSQL_OPT_RECONNECT, (const char*)&reconnect);
|
|
|
|
}
|
|
|
|
#endif
|
2005-10-28 01:34:24 +08:00
|
|
|
init_cmd = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_INIT_COMMAND, NULL TSRMLS_CC);
|
|
|
|
if (init_cmd) {
|
|
|
|
if (mysql_options(H->server, MYSQL_INIT_COMMAND, (const char *)init_cmd)) {
|
|
|
|
efree(init_cmd);
|
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
efree(init_cmd);
|
|
|
|
}
|
2009-09-22 23:31:35 +08:00
|
|
|
#ifndef PDO_USE_MYSQLND
|
2005-10-28 01:34:24 +08:00
|
|
|
default_file = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_FILE, NULL TSRMLS_CC);
|
|
|
|
if (default_file) {
|
|
|
|
if (mysql_options(H->server, MYSQL_READ_DEFAULT_FILE, (const char *)default_file)) {
|
|
|
|
efree(default_file);
|
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
efree(default_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
default_group= pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_GROUP, NULL TSRMLS_CC);
|
|
|
|
if (default_group) {
|
|
|
|
if (mysql_options(H->server, MYSQL_READ_DEFAULT_GROUP, (const char *)default_group)) {
|
|
|
|
efree(default_group);
|
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
efree(default_group);
|
|
|
|
}
|
2012-03-06 07:57:24 +08:00
|
|
|
#endif
|
2008-10-15 03:00:53 +08:00
|
|
|
compress = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_COMPRESS, 0 TSRMLS_CC);
|
|
|
|
if (compress) {
|
|
|
|
if (mysql_options(H->server, MYSQL_OPT_COMPRESS, 0)) {
|
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2012-03-06 07:57:24 +08:00
|
|
|
|
2011-04-15 22:24:40 +08:00
|
|
|
ssl_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_KEY, NULL TSRMLS_CC);
|
|
|
|
ssl_cert = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CERT, NULL TSRMLS_CC);
|
|
|
|
ssl_ca = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CA, NULL TSRMLS_CC);
|
|
|
|
ssl_capath = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CAPATH, NULL TSRMLS_CC);
|
|
|
|
ssl_cipher = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CIPHER, NULL TSRMLS_CC);
|
|
|
|
|
|
|
|
if (ssl_key || ssl_cert || ssl_ca || ssl_capath || ssl_cipher) {
|
|
|
|
mysql_ssl_set(H->server, ssl_key, ssl_cert, ssl_ca, ssl_capath, ssl_cipher);
|
|
|
|
if (ssl_key) {
|
|
|
|
efree(ssl_key);
|
|
|
|
}
|
|
|
|
if (ssl_cert) {
|
|
|
|
efree(ssl_cert);
|
|
|
|
}
|
|
|
|
if (ssl_ca) {
|
|
|
|
efree(ssl_ca);
|
|
|
|
}
|
|
|
|
if (ssl_capath) {
|
|
|
|
efree(ssl_capath);
|
|
|
|
}
|
|
|
|
if (ssl_cipher) {
|
|
|
|
efree(ssl_cipher);
|
|
|
|
}
|
|
|
|
}
|
2004-05-20 04:34:57 +08:00
|
|
|
}
|
2005-08-31 12:06:10 +08:00
|
|
|
|
2011-01-08 01:18:30 +08:00
|
|
|
#ifdef PDO_MYSQL_HAS_CHARSET
|
2011-01-07 22:58:23 +08:00
|
|
|
if (vars[0].optval && mysql_options(H->server, MYSQL_SET_CHARSET_NAME, vars[0].optval)) {
|
|
|
|
pdo_mysql_error(dbh);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-08-31 12:06:10 +08:00
|
|
|
dbname = vars[1].optval;
|
|
|
|
host = vars[2].optval;
|
|
|
|
if(vars[3].optval) {
|
|
|
|
port = atoi(vars[3].optval);
|
|
|
|
}
|
2005-02-10 09:34:39 +08:00
|
|
|
if (vars[2].optval && !strcmp("localhost", vars[2].optval)) {
|
2004-05-19 02:01:52 +08:00
|
|
|
unix_socket = vars[4].optval;
|
|
|
|
}
|
2008-07-21 21:09:28 +08:00
|
|
|
|
|
|
|
/* TODO: - Check zval cache + ZTS */
|
|
|
|
#ifdef PDO_USE_MYSQLND
|
|
|
|
if (dbname) {
|
|
|
|
dbname_len = strlen(dbname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dbh->password) {
|
|
|
|
password_len = strlen(dbh->password);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mysqlnd_connect(H->server, host, dbh->username, dbh->password, password_len, dbname, dbname_len,
|
2009-12-10 17:35:10 +08:00
|
|
|
port, unix_socket, connect_opts TSRMLS_CC) == NULL) {
|
2008-07-21 21:09:28 +08:00
|
|
|
#else
|
2005-07-03 05:01:38 +08:00
|
|
|
if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname, port, unix_socket, connect_opts) == NULL) {
|
2008-07-21 21:09:28 +08:00
|
|
|
#endif
|
2004-05-20 23:51:25 +08:00
|
|
|
pdo_mysql_error(dbh);
|
2004-05-19 02:01:52 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2006-03-17 08:15:09 +08:00
|
|
|
if (!dbh->auto_commit) {
|
|
|
|
mysql_handle_autocommit(dbh TSRMLS_CC);
|
|
|
|
}
|
2005-02-14 01:16:24 +08:00
|
|
|
|
2004-05-19 02:01:52 +08:00
|
|
|
H->attached = 1;
|
|
|
|
|
|
|
|
dbh->alloc_own_columns = 1;
|
|
|
|
dbh->max_escaped_char_length = 2;
|
2004-07-28 08:10:28 +08:00
|
|
|
dbh->methods = &mysql_methods;
|
2004-05-19 02:01:52 +08:00
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (i = 0; i < sizeof(vars)/sizeof(vars[0]); i++) {
|
|
|
|
if (vars[i].freeme) {
|
|
|
|
efree(vars[i].optval);
|
|
|
|
}
|
|
|
|
}
|
2004-07-28 08:10:28 +08:00
|
|
|
|
|
|
|
dbh->methods = &mysql_methods;
|
2004-05-19 02:01:52 +08:00
|
|
|
|
2008-07-21 21:09:28 +08:00
|
|
|
PDO_DBG_RETURN(ret);
|
2004-05-19 02:01:52 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
pdo_driver_t pdo_mysql_driver = {
|
|
|
|
PDO_DRIVER_HEADER(mysql),
|
|
|
|
pdo_mysql_handle_factory
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|