PHP Development
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Remember me

Go Back   Dev Articles Community ForumsProgrammingPHP Development

Add This Thread To:   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
Unread Dev Articles Community Forums Sponsor:
Old April 12th, 2013, 08:24 AM
GarryBrown GarryBrown is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
Join Date: Feb 2013
Posts: 7 GarryBrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 39 sec
Reputation Power: 0
Help needed with SQLite/PHP

Hello, I've written a code that menat to do the following:
I've got the form where users enters an URL link and a keyword. The website should be accessed and occurence of the keyword is counted and then the result is sent to a SQLite database. But the problem is the following:
every time I enter URL link, I receive a message:
Warning: file_get_contents( [function.file-get-contents]: failed to open stream: No such file or directory in E:\wwwroot\add.php on line 33
Could not open URL!
Any ideas on how to fix this bug? Thanks in advance.


//Open connection with a database
$db=sqlite_open("search.db", 0666, $sqliteerror);

$URL = $_POST['URL'];
$keyword = $_POST['keyword'];

//If no URL entered:
if( !$URL )
   die( "You need to define a URL to process." );

//Check whether entered URL is already recorded: 
$handle = sqlite_query($db,"SELECT page_id FROM page WHERE page_url = \"$URL\"");
$row = sqlite_fetch_array($handle, SQLITE_ASSOC );

if( $row['page_id'] )

//if yes, use old page_id:
   $page_id = $row['page_id'];
//If not, a new line containing URL is created:
sqlite_query($db,'INSERT INTO page (page_url) VALUES ("$URL")');
$page_id = sqlite_last_insert_rowid($db);

//Open URL contents and start parsing through the text for creating index in a database:
if( !($fd = file_get_contents($URL,"r")))
 die( "Could not open URL!" );

while( $buf = fgets($fd,1024) )
 //Extract all words matching the regexp from the current line: 

  // Loop through all words/occurrences and insert them into the database:
   for( $i = 0; $words[$i]; $i++ )
      for( $j = 0; $words[$i][$j]; $j++ )
         //Checking whether a current word already has a record in the database:
        $cur_word = addslashes( strtolower($words[$i][$j]) );
		$handle = sqlite_query($db,"SELECT word_id FROM word WHERE word_word = '$cur_word'");
		$row = sqlite_fetch_array($handle, SQLITE_ASSOC );
        if( $row['word_id'] )
            //if yes, the old word id is used:
            $word_id = $row['word_id'];
            //if not, a new word is created:
            sqlite_query($db,'INSERT INTO word (word_word) VALUES (\"$cur_word\")');
$page_id = sqlite_last_insert_rowid($db);

         //Registering the occurence of the word into a database:
sqlite_query($db,'INSERT INTO occurrence (word_id,page_id) 
                      VALUES ($word_id,$page_id)');


 //Searching the database of URL, keywords and occurencies of keywords:
   $handle = sqlite_query($db," SELECT p.page_url AS url,
                           COUNT(*) AS occurrences 
                           FROM page p, word w, occurrence o
                           WHERE p.page_id = o.page_id AND
                           w.word_id = o.word_id AND
                           w.word_word = \"$keyword\"
                           GROUP BY p.page_id
                           ORDER BY occurrences DESC
                           LIMIT $results" );
						    //Display of search results:
   print "<h2>Search results for '".$_POST['keyword']."':</h2>\n";
   for( $i = 1; $row = sqlite_fetch_array($handle); $i++ )
      print "$i. <a href='".$row['URL']."'>".$row['URL']."</a>\n";
      print "(occurrences: ".$row['occurrences'].")<br><br>\n";

Reply With Quote

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Help needed with SQLite/PHP

Developer Shed Advertisers and Affiliates

Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap