php - PDO SQLite3 connection failure when database is in different folder -
i'm trying connect sqlite3 database php, i'm hitting brick wall when want place db somewhere convenient , outside of web accesible space. when db file in same folder php script runs ok, when place somewhere else - silent fail.
i've written simple checker easier understand mean
<?php $files = array( 'data.db', getcwd() . directory_separator . 'data.db', 'some_inner_folder' . directory_separator . 'data.db', getcwd() . directory_separator . 'some_inner_folder' . directory_separator . 'data.db' ); foreach($files $file) { if(file_exists($file)) echo $file, ' found<br/>'; else echo $file, ' not found!<br/>'; try { $db = new pdo('sqlite:host=' . $file); if($db) echo 'connection ', $file, ' made succesfully<br/>'; } catch (pdoexception $error) { echo 'error connecting ', $file, ' error message: ', $error->getmessage(), '<br/>'; } $db = null; }
output turned out be:
data.db found connection data.db made succesfully c:\web\data.db found error connecting c:\web\data.db error message: sqlstate[hy000] [14] unable open database file some_inner_folder\data.db found error connecting some_inner_folder\data.db error message: sqlstate[hy000] [14] unable open database file c:\web\some_inner_folder\data.db found error connecting c:\web\some_inner_folder\data.db error message: sqlstate[hy000] [14] unable open database file
c:\web\data.db , c:\web\some_inner_folder\data.db has same contents (file copy&paste)
php version 5.3.6, windows 7 x64
pdo drivers mysql, sqlite, sqlite2
sqlite library 3.7.4
i'm not seeing why doesn't work.
problem solved
$db = new pdo('sqlite:host=' . $file);
should read this:
$db = new pdo('sqlite:' . $file);
turns out pdo_sqlite doesn't need 'host='
when coding database layer drupal 7 found pdo have many error modes , exception worth damn. $driver_options[pdo::attr_errmode] = pdo::errmode_exception;
make silent failure lot more noisy.
Comments
Post a Comment