derrida
asked on
can't connect to an sqlite database
hi
i am trying to work with sqlite but cannot connect to it. i have this code:
with firefox sqlite manager i have created a database named "company" in the folder where my sqlite3.exe is located.
i have an employees table.
then i try to run this and get:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 no such table: employees' in C:\xampp\htdocs\ronnyran\t estsqlite. php on line 15
what am i doing wrong?
i am trying to work with sqlite but cannot connect to it. i have this code:
// Create (connect to) SQLite database in file
$file_db = new PDO("sqlite:C:/sqlite/company.sqlite;dbname=company", "", "");
// Set errormode to exceptions
$file_db->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$result = $file_db->query('SELECT * FROM employees');
var_dump( $result );
with firefox sqlite manager i have created a database named "company" in the folder where my sqlite3.exe is located.
i have an employees table.
then i try to run this and get:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 no such table: employees' in C:\xampp\htdocs\ronnyran\t
what am i doing wrong?
ASKER
hi thanks for answering.
i put it inside a try catch like so:
and now i get nothing, but also the dump doesn't return anything.
i put it inside a try catch like so:
try{
// Create (connect to) SQLite database in file
$file_db = new PDO("sqlite:C:/sqlite/company.sqlite;dbname=company", "", "");
// Set errormode to exceptions
$file_db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$result = $file_db->query('SELECT * FROM employees');
var_dump( $result );
} catch (Exception $ex) {
$ex->getmessage();
}
and now i get nothing, but also the dump doesn't return anything.
ASKER
obviously forgot the echo :)
i get:
SQLSTATE[HY000]: General error: 1 no such table: employees
but i have it.
i get:
SQLSTATE[HY000]: General error: 1 no such table: employees
but i have it.
Doesn't SQLIte have a "Show tables" command? Something like this:
http://www.sqlite.org/faq.html#q7
Also, while we're debugging, it might be good to use multiple try{}catch{} blocks. And I think you want PDOException, not just general Exception. I think I would try it like this.
http://www.sqlite.org/faq.html#q7
Also, while we're debugging, it might be good to use multiple try{}catch{} blocks. And I think you want PDOException, not just general Exception. I think I would try it like this.
try{
$file_db = new PDO("sqlite:C:/sqlite/company.sqlite;dbname=company", "", "");
}
catch (PDOException $ex){
var_dump( $ex->getmessage() );
}
try{
$file_db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $ex){
var_dump( $ex->getmessage() );
}
try{
$result = $file_db->query('SELECT * FROM employees');
var_dump( $result );
}
catch (PDOException $ex){
var_dump( $ex->getmessage() );
}
ASKER
Interesting. I'm not seeing anything wrong. Can you do the queries manually in SQLite Manager?
ASKER
yes
What does phpinfo() say about PDO and SQLite? Also, this is a long shot, but do you have more than one SQLite database?
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
have no idea why but this morning everything works
Those are the scary ones!
Best regards, ~Ray
Best regards, ~Ray
http://php.net/manual/en/class.pdoexception.php