1--TEST-- 2PDO_sqlite: Testing PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES 3--EXTENSIONS-- 4pdo_sqlite 5--FILE-- 6<?php 7 8echo "Creating new PDO" . PHP_EOL; 9$db = new PDO('sqlite::memory:'); 10$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); 11 12$db->exec("CREATE TABLE dog ( id INTEGER PRIMARY KEY, name TEXT, annoying INTEGER )"); 13 14echo "Inserting first time which should succeed" . PHP_EOL; 15$db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); 16$errorInfo = $db->errorInfo(); 17echo sprintf("First Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL; 18 19echo "Inserting second time which should fail" . PHP_EOL; 20$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); 21$errorInfo = $db->errorInfo(); 22echo sprintf("Second Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL; 23 24 25echo "Creating new PDO with Extended Result Codes turned on" . PHP_EOL; 26$db = new PDO('sqlite::memory:', '', '', [PDO::SQLITE_ATTR_EXTENDED_RESULT_CODES => TRUE]); 27$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); 28 29$db->exec("CREATE TABLE dog ( id INTEGER PRIMARY KEY, name TEXT, annoying INTEGER )"); 30 31echo "Inserting first time which should succeed" . PHP_EOL; 32$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); 33$errorInfo = $db->errorInfo(); 34echo sprintf("First (Extended) Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL; 35 36echo "Inserting second time which should fail" . PHP_EOL; 37$result = $db->exec("INSERT INTO dog VALUES (1, 'Annoying Dog', 1)"); 38$errorInfo = $db->errorInfo(); 39echo sprintf("Second (Extended) Error Info: SQLSTATE Error Code: (%s), Driver Specific Error Code: (%s)", $errorInfo[0], $errorInfo[1]) . PHP_EOL; 40 41?> 42--EXPECT-- 43Creating new PDO 44Inserting first time which should succeed 45First Error Info: SQLSTATE Error Code: (00000), Driver Specific Error Code: () 46Inserting second time which should fail 47Second Error Info: SQLSTATE Error Code: (23000), Driver Specific Error Code: (19) 48Creating new PDO with Extended Result Codes turned on 49Inserting first time which should succeed 50First (Extended) Error Info: SQLSTATE Error Code: (00000), Driver Specific Error Code: () 51Inserting second time which should fail 52Second (Extended) Error Info: SQLSTATE Error Code: (HY000), Driver Specific Error Code: (1555) 53