开发者

read sqlite from php

开发者 https://www.devze.com 2023-04-12 15:07 出处:网络
I\'m trying to read a simple sqlite database using php. The php code looks like this: <?php echo \"<b>PHP Test</b> <br>\";

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()){
/*...*/
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号