Question

my problem it's quite simple.

I'm trying to make a script for dump information from one table in firebird to another in SQLite.

I'm able to do all the process but what I'm not able to do is to create a persistent sqlite database. I launch this script on my computer (Ubuntu 13.04) in "/var/www/PabloLab/experiments" and I don't know where creates the file or if it's created.

The full script:

/*
 * Preparing SQLite db
 */

$dbname = 'langs.sqlite';
$my_table = 'LANG';

$db = new SQLite3($dbname, 0666);    
$query = "CREATE TABLE $my_table (ID INTEGER NOT NULL,
                                  TXT VARCHAR,
                                  LANG_ID NUMERIC NOT NULL)";
$success = $db->exec($query);    
$stmt = "SELECT r.ID, r.TXT, r.LANG_ID
         FROM VLANG r
         WHERE r.ID in (1,3)";
$sql = EF_sql_connection($stmt, MY_FIREBIRD_DB); //It works perfect, no problem here.
while ($lang_info = ibase_fetch_assoc($sql)) {
    $lang = utf8_encode($lang_info["TXT"]);
    $id = utf8_encode($lang_info["ID"]);
    $lang_id = utf8_encode($lang_info["LANG_ID"]);
    $stmt_sqlite = "INSERT INTO $my_table VALUES ($id, '$lang', $lang_id)";
    $success = $db->exec($stmt_sqlite);
}
$result = $db->query("SELECT * FROM $my_table");
while($row = $result->fetchArray()){
    $id = $row["ID"];
    $txt = $row["TXT"];
    $lang_id = $row["LANG_ID"];
    echo "$id - $txt - $lang_id<br>";
}

Thanks for your help and your time.

Regards.

Was it helpful?

Solution

(Just copying my comment that solved @reverendocabron's problem for easy reference.)

The $flags argument is expected to be SQLITE3_OPEN_READONLY, SQLITE3_OPEN_READWRITE and/or SQLITE3_OPEN_CREATE (whose values are really 1, 2 and 4 respectively) while you give it a Unix-style 0666 argument. In your case, I guess what you're looking for is really SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE which happens to be the default. Try removing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top