I have an SQLite database and am trying to connect to it with PHP. This is what I'm using:
<?php $dbconn = sqlite_open('combadd.sqlite'); if ($dbconn) { $result = sqlite_query($dbconn, "SELECT * FROM combo_calcs WHERE options='easy'"); var_dump(sqlite_fetch_array($result, SQLITE_ASSOC)); } else { print "Connection to database failed!\n"; } ?>
However, I get this error:
Warning:
sqlite_open()
[function.sqlite-open]: file is encrypted or is not a database inC:\xampp\htdocs\deepthi\combadd\combadd_db.php
on line 4
Connection to database failed!
What's wrong and how can I fix it?
Try to use PDO instead of sqlite_open:
$dir = 'sqlite:/[YOUR-PATH]/combadd.sqlite'; $dbh = new PDO($dir) or die("cannot open the database"); $query = "SELECT * FROM combo_calcs WHERE options='easy'"; foreach ($dbh->query($query) as $row) { echo $row[0]; } $dbh = null; //This is how you close a PDO connection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With