New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new PDO mysql connection attr to control multi statements option #896
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c2cdbf7
Start adding new attribute to control multi statements
pwolanin d6949b0
add new constant to test
pwolanin bf776eb
add test case for new connection attribute
pwolanin 61d53a3
Take out php6 style expect strings and add more checks to the test
pwolanin 294bfb1
add additional test verifying multiple result proc still works when l…
pwolanin 3580271
Add a check for a single statement with trailing delimiter
pwolanin e800bdb
Add output at the top of the foreach loop to make debugging easier
pwolanin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,8 +172,9 @@ enum { | |
PDO_MYSQL_ATTR_SSL_CAPATH, | ||
PDO_MYSQL_ATTR_SSL_CIPHER, | ||
#if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND) | ||
PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY | ||
PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY, | ||
#endif | ||
PDO_MYSQL_ATTR_MULTI_STATEMENTS, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, this needs to be behind a MYSQL_VERSION_ID check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above - this should not be needed - supported by Mysql 4.1 |
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--TEST-- | ||
PDO::MYSQL_ATTR_MULTI_STATEMENTS | ||
--SKIPIF-- | ||
<?php | ||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); | ||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); | ||
MySQLPDOTest::skip(); | ||
$db = MySQLPDOTest::factory(); | ||
?> | ||
--INI-- | ||
error_reporting=E_ALL | ||
--FILE-- | ||
<?php | ||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); | ||
|
||
$dsn = MySQLPDOTest::getDSN(); | ||
$user = PDO_MYSQL_TEST_USER; | ||
$pass = PDO_MYSQL_TEST_PASS; | ||
|
||
$table = sprintf("test_%s", md5(mt_rand(0, PHP_INT_MAX))); | ||
$db = new PDO($dsn, $user, $pass); | ||
$db->exec(sprintf('DROP TABLE IF EXISTS %s', $table)); | ||
$create = sprintf('CREATE TABLE %s(id INT)', $table); | ||
$db->exec($create); | ||
$db->exec(sprintf('INSERT INTO %s(id) VALUES (1)', $table)); | ||
$stmt = $db->query(sprintf('SELECT * FROM %s; INSERT INTO %s(id) VALUES (2)', $table, $table)); | ||
$stmt->closeCursor(); | ||
$info = $db->errorInfo(); | ||
var_dump($info[0]); | ||
$stmt = $db->query(sprintf('SELECT id FROM %s', $table)); | ||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); | ||
// A single query with a trailing delimiter. | ||
$stmt = $db->query('SELECT 1 AS value;'); | ||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); | ||
|
||
// New connection, does not allow multiple statements. | ||
$db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_MULTI_STATEMENTS => false)); | ||
$stmt = $db->query(sprintf('SELECT * FROM %s; INSERT INTO %s(id) VALUES (3)', $table, $table)); | ||
var_dump($stmt); | ||
$info = $db->errorInfo(); | ||
var_dump($info[0]); | ||
|
||
$stmt = $db->query(sprintf('SELECT id FROM %s', $table)); | ||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); | ||
// A single query with a trailing delimiter. | ||
$stmt = $db->query('SELECT 1 AS value;'); | ||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); | ||
|
||
$db->exec(sprintf('DROP TABLE IF EXISTS %s', $table)); | ||
print "done!"; | ||
?> | ||
--EXPECTF-- | ||
string(5) "00000" | ||
array(2) { | ||
[0]=> | ||
array(1) { | ||
["id"]=> | ||
string(1) "1" | ||
} | ||
[1]=> | ||
array(1) { | ||
["id"]=> | ||
string(1) "2" | ||
} | ||
} | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["value"]=> | ||
string(1) "1" | ||
} | ||
} | ||
bool(false) | ||
string(5) "42000" | ||
array(2) { | ||
[0]=> | ||
array(1) { | ||
["id"]=> | ||
string(1) "1" | ||
} | ||
[1]=> | ||
array(1) { | ||
["id"]=> | ||
string(1) "2" | ||
} | ||
} | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["value"]=> | ||
string(1) "1" | ||
} | ||
} | ||
done! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be guarded like the previous constant — we still support MySQL 4.1 (not entirely clear on why, admittedly), and it doesn't support CLIENT_MULTI_STATEMENTS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the connection code is guarded with:
not by MySQL version. In fact, it looks like the 4.1 API supports it:
http://dev.mysql.com/doc/refman/4.1/en/c-api-multiple-queries.html
So, I think guarding the constant with the same check would make sense, though I'm not sure at this point when it would be undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I got tricked by a sentence in the MySQL 5.0 manual implying it was new in that version. Sorry about that! Disregard what I said.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so does it make sense to guard the class constant using
or since it would be ignored if somehow that wan't defined, it's better to always define it to avoid PHP code having to check if it exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're sure it's always defined in MySQL >= 4.1, then let's not bother with the #ifdef. No point cluttering the code unnecessarily. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's actually defined by default by mysqlnd:
It's also available in the C API since January 2003
http://bazaar.launchpad.net/~mysql/libmysql/1.0/view/1412/include/mysql_com.h#L109
http://bazaar.launchpad.net/~mysql/libmysql/1.0/revision/1403.62.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, my conclusion is we really don't need the #ifdef anywhere any more, but I guess leaving it in where it is might be fine for now.