function testDb_SqliteInsertUpdateSelect() { $Db_Sqlite3 = new A_Db_Sqlite3(array('filename' => $this->filename)); $Db_Sqlite3->connect(); $test_rows = array(0 => array(':id' => 10, ':name' => 'Foo'), 1 => array(':id' => 20, ':name' => 'Bar')); $sql = "CREATE TABLE test1 (id INT, name VARCHAR(100))"; $Db_Sqlite3->query($sql); $this->assertFalse($Db_Sqlite3->isError()); $this->assertTrue($Db_Sqlite3->getErrorMsg() == ''); foreach ($test_rows as $row) { $result = $Db_Sqlite3->query("INSERT INTO test1 (id, name) VALUES (:id, ':name')", $row); $this->assertFalse($Db_Sqlite3->isError()); $this->assertTrue($Db_Sqlite3->getErrorMsg() == ''); } $result = $Db_Sqlite3->query("SELECT * FROM test1"); #dump($result, 'RESULT: ', 1); $this->assertFalse($Db_Sqlite3->isError()); $this->assertTrue($Db_Sqlite3->getErrorMsg() == ''); $rows = $result->fetchAll(); #dump($rows, 'ROWS: ', 1); foreach ($rows as $n => $row) { $this->assertTrue($test_rows[$n]['id'] == $row['id']); $this->assertTrue($test_rows[$n]['name'] == $row['name']); } #dump($Db_Sqlite3->getSql(), 'SQL HISTORY: ', 1); $Db_Sqlite3->close(); }
<?php include 'config.php'; $filename = 'sqlite3.db'; $db = new A_Db_Sqlite3(array('filename' => $filename)); $db->connect(); if (!$db->isError()) { $test_rows = array(0 => array(':id' => 10, ':name' => 'Foo'), 1 => array(':id' => 20, ':name' => 'Bar')); $sql = "CREATE TABLE test1 (id INT, name VARCHAR(100))"; $db->query($sql); foreach ($test_rows as $row) { $result = $db->query("INSERT INTO test1 (id, name) VALUES (:id, ':name')", $row); } $sql = "SELECT * FROM test1"; $result = $db->query($sql); if (!$db->isError()) { $row = $result->fetchAll(); dump($row, 'ROW: '); } else { echo 'connect ERROR: ' . $db->getErrorMsg(); } } else { echo 'connect ERROR: ' . $db->getErrorMsg(); } $db->close(); unlink($filename); dump();