Results 1 to 8 of 8

Thread: SQLite help?

  1. #1
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default SQLite help?

    Hi, I've been following tutorials and trying to build a table using data from a SQLite database. The page in question is here.

    So far, I can't get my page to successfully open the database (dies where highlighted). the code:
    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
    Last edited by traq; 04-29-2009 at 01:49 AM.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I'll try that. "sqlite_connect" isn't in the tutorial I'm using, though, and it's not in the php.net sqlite functions list, either.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    no luck! anyone else have any ideas?

    BTW, I've been looking through other tutorials also and they all seem to indicate that
    Code:
    sqlite_open($dbname)
    both connects and opens/ creates the database, so no other "connect" command is required.
    Last edited by traq; 04-30-2009 at 01:17 AM.

  5. #5
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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

  6. #6
    Join Date
    Apr 2009
    Location
    India
    Posts
    41
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    I looked here http://us2.php.net/manual/en/function.sqlite-open.php and saw these comments.
    i agree this piont.....................

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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...

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •