diff options
author | Wez Furlong <wez@php.net> | 2006-04-09 08:11:31 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2006-04-09 08:11:31 +0000 |
commit | b9f85f37cc867b9afe1a6c7114e165a0d44e62f9 (patch) | |
tree | 950912fcc9b4547d225b124dc7691a4d7b2d2d35 /ext/pdo_mysql | |
parent | 687e6ffc582291149f38cae628d24a5f426d846e (diff) | |
download | php-git-b9f85f37cc867b9afe1a6c7114e165a0d44e62f9.tar.gz |
Fixed Bug #36602: persistent connections don't work with MySQL 5.0.3+.
Fixed PECL Bug #6262; correctly fallback to emulated statements
when the server version is too old.
Also include code to default to using emulated prepared statements, as these
can take advantage of the query cache. Since it's a bit late in the release
process to spring this on the masses, the default has not been changed. The
code is included so that it doesn't get lost.
Diffstat (limited to 'ext/pdo_mysql')
-rwxr-xr-x | ext/pdo_mysql/mysql_driver.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 9ffa80ad5d..51e502ccaa 100755 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -163,6 +163,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, char *nsql = NULL; int nsql_len = 0; int ret; + int server_version; #endif S->H = H; @@ -173,11 +174,11 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, goto end; } - /* TODO: add runtime check to determine if the server we are talking to supports - * prepared statements; if it doesn't, we should set stmt->supports_placeholders - * to PDO_PLACEHOLDER_NONE, and have the rest of the code look at S->stmt to - * determine if we're using real prepared statements or the PDO emulated version */ #if HAVE_MYSQL_STMT_PREPARE + server_version = mysql_get_server_version(H->server); + if (server_version < 40100) { + goto fallback; + } stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL; ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len TSRMLS_CC); @@ -318,6 +319,7 @@ static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_D ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = Z_BVAL_P(val); 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); return 1; default: @@ -431,6 +433,17 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ H->einfo.errcode = 0; H->einfo.errmsg = NULL; + /* at the time of writing, the mysql documentation states: + * http://mysql.localhost.net.ar/doc/refman/5.0/en/query-cache-how.html + * "A query also is not cached under these conditions: + * ... + * It was issued as a prepared statement, even if no placeholders were employed." + * + * We default to emulating prepared statements + * in order to take advantage of the query cache +FIXME: H->emulate_prepare = 1; a bit risky to do this so late in the RC, so defer it. + */ + /* allocate an environment */ /* handle for the server */ @@ -449,7 +462,12 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ char *init_cmd = NULL, *default_file = NULL, *default_group = NULL; H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 0 TSRMLS_CC); - H->emulate_prepare = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_DIRECT_QUERY, 0 TSRMLS_CC); + + 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); + H->max_buffer_size = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_MAX_BUFFER_SIZE, H->max_buffer_size TSRMLS_CC); if (mysql_options(H->server, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout)) { @@ -462,6 +480,15 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ goto cleanup; } +#ifdef MYSQL_OPT_RECONNECT + /* since 5.0.3, the default for this option is 0 if not specified. + * we want the old behaviour */ + { + long reconnect = 1; + mysql_options(H->server, MYSQL_OPT_RECONNECT, (const char*)&reconnect); + } +#endif + 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)) { |