Log in

View Full Version : SQLite help?



traq
04-28-2009, 09:23 PM
Hi, I've been following tutorials and trying to build a table using data from a SQLite database. The page in question is here (http://www.custom-anything.com/reel/demo/moulding.php).

So far, I can't get my page to successfully open the database (dies where highlighted). the code:


<?php
$db = "rls.sqlite";

$handle = sqlite_open($db) or die ("Unable to open database");

if ((isset($_POST['sort'])) && $_POST['sort'] == 'riverside' || 'anaheim'){
$query = "SELECT * FROM TableMoulding WHERE stocking LIKE %".$_POST['sort']."% ORDER BY part";
}
elseif ((isset($_POST['sort'])) && $_POST['sort'] != 'all'){
$query = "SELECT * FROM TableMoulding WHERE remark LIKE %".$_POST['sort']."% ORDER BY part";
}
else {
$query = "SELECT * FROM TableMoulding ORDER BY part";
}

$result = sqlite_query($handle, $query) or die ("Error in query");

function TableMoulding(){
echo "<div id=\"moulding\">";
echo "<table>";
echo "<tr>";
echo "<th>Profile</th>";
echo "<th>Species</th>";
echo "<th>Dimensions</th>";
echo "<th>Stocking Locations</th>";
echo "<th>Remarks</th>";
echo "</tr>";
while ($row = sqlite_fetch_array($result)){
echo "<tr>";
echo "<td>
<a href=\"/reel/library/images/moulding/det".$row['part']."\.png\" rel=\"facebox\">
<img src=\"/reel/library/images/moulding/det".$row['part']."\.png\" height=\"100px\" width=\"100px\" alt=\"Detail ".$row['part']."</a><br>
Detail ".$row['part']."</td>";
echo "<td>".$row['species']."</td>";
echo "<td>".$row['dimensions']."</td>";
echo "<td>".$row['stocking']."</td>";
echo "<td>".$row['remark']."</td>";
echo "</tr>";
}
echo "</table>";
}

if (sqlite_num_rows($result) > 0){
TableMoulding();
}
else {
die ("No results found");
}
?>


I'm sure there are other problems too, so if you see anything, please let me know; but that's where I'm stuck right now. Thanks!

[edit]: Should this be in the php forum? Mods, please move it if so. thanks again

forum_amnesiac
04-29-2009, 07:54 AM
I use MYSQL but I assume SQLite is similar.

Have you connected to the database in queston?

In MYSQL you have to use a connect statement like this:-

mysql_connect('hostname, 'username', 'password');

before you try to open the database.

traq
04-29-2009, 02:32 PM
I'll try that. "sqlite_connect" isn't in the tutorial (http://devzone.zend.com/node/view/id/644) I'm using, though, and it's not in the php.net sqlite functions (http://us.php.net/manual/en/function.sqlite-array-query.php) list, either.

traq
04-30-2009, 01:08 AM
no luck! anyone else have any ideas?

BTW, I've been looking through other tutorials also and they all seem to indicate that
sqlite_open($dbname) both connects and opens/ creates the database, so no other "connect" command is required.

forum_amnesiac
04-30-2009, 07:54 AM
I looked here http://us2.php.net/manual/en/function.sqlite-open.php and saw these comments.

"I found that both the file and the directory it is in have to be writeable by the web server, or an ambiguous "unable to open database file" error appears (pecl 1.0.3). I pulled my hair out for ages before I realised that."

"Since sqlite uses a journal to do updates and inserts (and creates it on the fly), you ALSO must have write permissions set for the web server to write in the same DIRECTORY as the database file. "

The only other thing I can think of is to check that the Db is in the same directory as your PHP.

Hope this helps, sorry if not

amutha
04-30-2009, 09:08 AM
I looked here http://us2.php.net/manual/en/function.sqlite-open.php and saw these comments.

i agree this piont.....................

traq
05-01-2009, 12:13 AM
Actually, I just got an answer from my webhost. 1and1 internet apparently has the SQLite libraries switched off. I couldn't get a direct answer about why (SQLite is bundled and enabled by default in PHP5), but I would assume it has something to do with the fact that you get 5 MySQL databases in your basic hosting package and have to pay extra to get more. whatever. the portability of SQLite really appealed to me, I guess I'll have to go with the heavyweight solution for now... :(

traq
05-01-2009, 12:34 AM
well... crap. wait a minute. my PHP configuration info says, not only that I've got php 4.4.9 (the package is supposed to come with PHP5), but that SQLite is enabled. So I'm back to square one, which, unfortunately, involves not going through the trouble of talking with tech support. :( :(