github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/acceptance/testdata/php/test.php (about) 1 <?php 2 3 function kill($msg) { 4 echo($msg); 5 exit(1); 6 } 7 8 $dbconn = pg_connect('') 9 or kill('Could not connect: ' . pg_last_error()); 10 $result = pg_query_params('SELECT 1, 2 > $1, $1', [intval($argv[1])]) 11 or kill('Query failed: ' . pg_last_error()); 12 $arr = pg_fetch_row($result); 13 ($arr === ['1', 'f', '3']) or kill('Unexpected: ' . print_r($arr, true)); 14 15 $dbh = new PDO('pgsql:','root', null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); 16 $dbh->exec('CREATE database bank'); 17 $dbh->exec('CREATE table bank.accounts (id INT PRIMARY KEY, balance INT)'); 18 $dbh->exec('INSERT INTO bank.accounts (id, balance) VALUES (1, 1000), (2, 250)'); 19 $dbh->beginTransaction(); 20 $stmt = $dbh->prepare('UPDATE bank.accounts SET balance = balance + :deposit WHERE id=:account'); 21 $stmt->execute(array('account' => 1, 'deposit' => 10)); 22 $stmt->execute(array('account' => 2, 'deposit' => -10)); 23 $dbh->commit();