예제 #1
0
 function testDb_SqLiteInsertUpdateSelect()
 {
     $Db_Sqlite = new A_Db_Sqlite(array('filename' => $this->filename));
     $Db_Sqlite->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_Sqlite->query($sql);
     $this->assertFalse($Db_Sqlite->isError());
     $this->assertTrue($Db_Sqlite->getErrorMsg() == '');
     foreach ($test_rows as $row) {
         $result = $Db_Sqlite->query("INSERT INTO test1 (id, name) VALUES (:id, ':name')", $row);
         $this->assertFalse($Db_Sqlite->isError());
         $this->assertTrue($Db_Sqlite->getErrorMsg() == '');
     }
     $result = $Db_Sqlite->query("SELECT * FROM test1");
     #dump($result, 'RESULT: ', 1);
     $this->assertFalse($Db_Sqlite->isError());
     $this->assertTrue($Db_Sqlite->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_Sqlite->getSql(), 'SQL HISTORY: ', 1);
     $Db_Sqlite->close();
 }
예제 #2
0
<?php

include 'config.php';
$filename = 'sqlite.db';
$db = new A_Db_Sqlite(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);