SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast gdhanasekar's Avatar
    Join Date
    Feb 2006
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I search the text in whole mysql DB?

    HI,

    How do I search the text in whole mysql DB instead of one table?

    Regards!
    Dhanasekar.G

  2. #2
    I Never Give Up roosevelt's Avatar
    Join Date
    May 2005
    Posts
    515
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't know if there's any SQL Query available to search the whole database but you should specify the tables and the items you wish to select. Here's a PHP Code to make things easier for you.

    PHP Code:
    <?php

    $connect 
    mysql_connect('host''username''password');

    if(
    $connect)
    {

        
    $selectdb mysql_select_db('dbname'$connect);

        if(
    $selectdb)
        {
            
    $sql "SHOW TABLES FROM $dbname";
            
    $result mysql_query($sql);

            
    $tables = array();

            
    $i 0;

            while(
    $data mysql_fetch_array($result))
            {
                
    $tables[] = $data[$i];
                
    $i++;
            }

            
    $tableslist implode(","$tables); //makes table1,table2

            
    $searchquery mysql_query("SELECT * FROM $tableslist WHERE MATCH (colname,colnametwo) AGAINST ('keyword' IN NATURAL LANGUAGE MODE)");
            
            
    //Do a similar While Loop like above :p

        
    }

    }

    ?>

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you can only use MATCH syntax on one table at a time

    and if there is no fulltext index declared, you get a table scan

    gdhanasekar, the best approach is to understand why you feel you need to search the whole database

    can you be a bit more specific about your requirement?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •