Page 1 of 1

Full-text search

Posted: Mon Jun 16, 2008 1:25 pm
by zed420
Hi All
I wonder if you could help me I'm trying to write a programm for Full-text search but I can not seem to get the query right. error says it can not connect to databse. Here is my code

Code: Select all

<?php
        $database = "sampledb";
        $user = "xxxxxxxx";
        $pass = "xxxxxx";
        $hostname = "localhost";
        $table = "itemtb";
    
    $db = mysql_connect("$hostname", "$user","$pass");
    mysql_select_db("$database");
 
   // If the form has been submitted with supplied keywords
   if (isset($_POST['keywords'])) {
      // Connect to server and select database
 
      $keywords = $_POST['keywords'];
 
      // Create the query
$query= "SELECT ItemName FROM itemtb WHERE MATCH(ItemName) against(`$keywords`)";
 $result = mysql_query($query)
       or die ("Couldn't execute query for collecting your data.");
    
?>
<TABLE BORDER=0 WIDTH=90% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#99CC99">
<TR ALIGN=CENTER bgcolor="#CCFF66">
<td><font color=red><b>Item name</font></TD>
</tr>
<?
    while ($row = mysql_fetch_array($result))  {
    extract($row);
        echo "<tr align=center>
        <td>" . $row['ItemName'] . "</td>
        </tr>";
    }
?></table><?
   }
?>
<p>
<form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>">
      Keywords:<br />
      <input type="text" name="keywords" size="20" maxlength="40" value="" /><br />
      <input type="submit" value="Search!">
   </form>
 
On same script if I use different query it works fine for example if I take off MATCH and AGAINST and just leave it to show all ItemName it works.

Zed

Re: Full-text search

Posted: Mon Jun 16, 2008 1:27 pm
by VladSun
What is the type of tables you use - MyISAM or InnoDB?

Re: Full-text search

Posted: Mon Jun 16, 2008 1:29 pm
by zed420
MyISAM

thanks for looking at my post
Zed

Re: Full-text search

Posted: Mon Jun 16, 2008 1:33 pm
by VladSun
Hm, I see you are using backquotes in the query - try using single quotes.
Also, have a look at this:
http://www.petefreitag.com/item/477.cfm

Re: Full-text search

Posted: Mon Jun 16, 2008 11:14 pm
by lonelywolf
have you set FULLTEXT for columns you want to apply fulltext search?

Re: Full-text search

Posted: Tue Jun 17, 2008 9:49 am
by pickle
If the error you're getting says you can't connect to the database, then it has nothing to do with your query, and everything to do with how you're trying to connect. Check your credentials.

Also, you don't need to pass your credentials in double-quotes.