mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
Add simple tests for insert through PDO::prepare/PDOStatement::execute.
Tests both question mark placeholders and named parameters.
This commit is contained in:
parent
570976d236
commit
83dfcbf3f6
42
ext/pdo/tests/pdo_021.inc
Executable file
42
ext/pdo/tests/pdo_021.inc
Executable file
@ -0,0 +1,42 @@
|
||||
<?php # vim:ft=php
|
||||
|
||||
require_once('pdo.inc');
|
||||
|
||||
set_sql('create1', 'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
|
||||
set_sql('insert1', "INSERT INTO test VALUES(?, ?, ?)");
|
||||
set_sql('insert2', "INSERT INTO test VALUES(:first, :second, :third)");
|
||||
set_sql('select', 'SELECT COUNT(*) FROM test');
|
||||
|
||||
$data = array(
|
||||
array('10', 'Abc', 'zxy'),
|
||||
array('20', 'Def', 'wvu'),
|
||||
array('30', 'Ghi', 'tsr'),
|
||||
array('40', 'Jkl', 'qpo'),
|
||||
array('50', 'Mno', 'nml'),
|
||||
array('60', 'Pqr', 'kji'),
|
||||
);
|
||||
|
||||
$DB->exec($SQL['create1']);
|
||||
|
||||
// Insert using question mark placeholders
|
||||
$stmt = $DB->prepare($SQL['insert1']);
|
||||
foreach ($data as $row) {
|
||||
$stmt->execute($row);
|
||||
}
|
||||
|
||||
$select = $DB->query($SQL['select']);
|
||||
$num = $select->fetchSingle();
|
||||
echo 'There are ' . $num . " rows in the table.\n";
|
||||
|
||||
// Insert using named parameters
|
||||
$stmt2 = $DB->prepare($SQL['insert2']);
|
||||
foreach ($data as $row) {
|
||||
$stmt2->execute(array(':first'=>($row[0] + 5), ':second'=>$row[1],
|
||||
':third'=>$row[2]));
|
||||
}
|
||||
|
||||
$select = $DB->query($SQL['select']);
|
||||
$num = $select->fetchSingle();
|
||||
echo 'There are ' . $num . " rows in the table.\n";
|
||||
|
||||
?>
|
20
ext/pdo_odbc/tests/pdo_021.phpt
Executable file
20
ext/pdo_odbc/tests/pdo_021.phpt
Executable file
@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
PDO_ODBC: PDOStatement::execute with parameter markers.
|
||||
--SKIPIF--
|
||||
<?php # vim:ft=php
|
||||
require_once('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once('connection.inc');
|
||||
require_once('prepare.inc');
|
||||
|
||||
require_once($PDO_TESTS . 'pdo_021.inc');
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
<?php exit(0); ?>
|
||||
--EXPECT--
|
||||
There are 6 rows in the table.
|
||||
There are 12 rows in the table.
|
||||
===DONE===
|
Loading…
Reference in New Issue
Block a user