read sqlite from php
I'm trying to read a simple sqlite database using php. The php code looks like this:
<?php
echo "<b>PHP Test</b> <br>";
echo "before loading<br>";
$db="/var/www/test.sqlite";
echo "assigned $db<br>";
try{
echo "in try <br>";
$database= sqlite_open($db,0666,$error);
echo "after open $error <br>";
}catch(Exception $e)
{
echo "fail ";
die($error);
}
$query="SELECT Serial FROM TxPlugins";
$result = sqlite_query($database, "SELECT * FROM TxPlugins");
echo "<br>after query $result <br>";
while($row=sqlite_fetch_array($result)){
echo "$row <br>";
}
sqlite_close($sqlite_Db);
?>
The sqlite3 I can read the file and do the same select. I always get the error:
file is encrypt开发者_StackOverflowed or is not a database
what's wrong?
Try to use PDO - http://php.net/manual/ru/ref.pdo-sqlite.php
$db = new PDO('sqlite:mydatabase.sqlite');
$query=$this->db->prepare("SELECT Serial FROM TxPlugins");
$query->execute();
while($row = $r->fetchObject()){
/*...*/
}
精彩评论