forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PDOStatement::activeQueryString()
- Loading branch information
1 parent
ee38e01
commit 83086d9
Showing
3 changed files
with
82 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--TEST-- | ||
PDO Common: PDOStatement::activeQueryString() | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('pdo')) die('skip'); | ||
$dir = getenv('REDIR_TEST_DIR'); | ||
if (false == $dir) die('skip no driver'); | ||
require_once $dir . 'pdo_test.inc'; | ||
PDOTest::skip(); | ||
|
||
$db = PDOTest::factory(); | ||
if (!$db->getAttribute(PDO::ATTR_EMULATE_PREPARES) && !$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true)) die('skip driver cannot emulate prepared statements'); | ||
?> | ||
--FILE-- | ||
<?php | ||
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/'); | ||
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; | ||
|
||
$db = PDOTest::factory(); | ||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); | ||
|
||
$stmt = $db->query('SELECT 1'); | ||
var_dump($stmt->activeQueryString()); // works with statements without bound values | ||
|
||
$stmt = $db->prepare('SELECT :bool, :int, :string, :null'); | ||
$stmt->bindValue(':bool', true, PDO::PARAM_BOOL); | ||
$stmt->bindValue(':int', 123, PDO::PARAM_INT); | ||
$stmt->bindValue(':string', 'foo', PDO::PARAM_STR); | ||
$stmt->bindValue(':null', null, PDO::PARAM_NULL); | ||
|
||
var_dump($stmt->activeQueryString()); // will return unparsed query before execution | ||
|
||
$stmt->execute(); | ||
var_dump($stmt->activeQueryString()); // will return parsed query after execution | ||
var_dump($stmt->activeQueryString()); // can be called repeatedly | ||
|
||
$stmt->execute(); | ||
var_dump($stmt->activeQueryString()); // works if the statement is executed again | ||
|
||
$stmt->bindValue(':int', 456, PDO::PARAM_INT); | ||
$stmt->execute(); | ||
var_dump($stmt->activeQueryString()); // works with altered values | ||
|
||
?> | ||
--EXPECT-- | ||
string(8) "SELECT 1" | ||
string(34) "SELECT :bool, :int, :string, :null" | ||
string(26) "SELECT 1, 123, 'foo', NULL" | ||
string(26) "SELECT 1, 123, 'foo', NULL" | ||
string(26) "SELECT 1, 123, 'foo', NULL" | ||
string(26) "SELECT 1, 456, 'foo', NULL" |
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