1

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.

reverendocabron
  • 189
  • 1
  • 10
  • Try adding a `$db->close();` statement at the very end of your PHP file. If that's not the problem, at least it's good form to do so. Also, make sure your code does not throw any exceptions. – SolarBear Oct 18 '13 at 12:24
  • Thanks for the advice, but it was not the solution . P.S. I really forgot to close the connection ;) – reverendocabron Oct 18 '13 at 15:42
  • I tried a much simpler test (http://pastebin.com/9QS4k29k) on my machine and the database file gets created correctly in the same directory as the script - although this is a Windows machine. Make sure PHP has write access to that directory or explicitly specify one it has write acccess to. – SolarBear Oct 18 '13 at 18:46
  • 1
    Also, 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 respectiively) 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. – SolarBear Oct 18 '13 at 18:47
  • 1
    Removing 0666 argument make it work perfect. Thank you everyone for your time and answers. – reverendocabron Oct 21 '13 at 08:56

1 Answers1

0

(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.

SolarBear
  • 4,534
  • 4
  • 37
  • 53