vendredi 10 avril 2015

Connecting to a remote SQLite database with PHP

I'm trying to connect to a SQLite database that is not local to my web server. This is all being done on an intranet, so my web server is at 192.168.10.15, while the database is at 192.168.10.76. I'm using the following script:



<?php

class MyDB extends SQLite3
{
function __construct()
{
$this->open('192.168.10.76/MyDevDB.db3');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
}


?>


I know the script works because I can connect to a database on my local machine. When I try to connect to the db on .10.76, it gives the following error:



Fatal error: Uncaught exception 'Exception' with message 'Unable to open database: unable to open database file' in /


My initial thought is that the database has to be set to accept remote connections, similar to what you would do with a MySQL database. My next thought is that there is a username and password (which would be the same as all our other dev stuff) for the database and I don't know how to properly pass those values in the script. I tried:



$this->open('192.168.10.76/MyDevDB.db3','myUsualUsername','myUsualPassword');


But that didn't help either.


Am I on the right track? I'm getting the feeling that SQLite doesn't work the same as MySQL/MSSQL. Since there's no server, can there even be a username/password? Any ideas?


Aucun commentaire:

Enregistrer un commentaire