search one keyword from all tables;

 

 <?php /** @author Jevons zeng email: <[email protected]> skype: booksoft2008ay msn: [email protected] @version 1.0 **/ class searchdb { private $dbserver; private $dbuser; private $dbpass; private $dbname; public function __construct( $dbserver, $dbuser, $dbpass, $dbname){ $this->dbserver = $dbserver; $this->dbuser = $dbuser; $this->dbpass = $dbpass; $this->dbname = $dbname; } public function searchdb($keyword) { set_time_limit(0); $ret=""; $link=mysql_connect($this->dbserver,$this->dbuser, $this->dbpass); if(mysql_select_db($this->dbname)==false) { echo 'mysql_select_db failed'; die('database select failed'); } mysql_query("SET NAMES 'utf8'"); $sql="SHOW TABLES"; $result = mysql_query($sql); $tablesnames=array(); while( $result && $row = mysql_fetch_array($result)) { $tablesnames[]= $row['Tables_in_'.$this->dbname]; } mysql_free_result($result); for($t=0;$t<count($tablesnames);$t++) { $tablename=$tablesnames[$t]; $fields = mysql_list_fields ( $this->dbname , $tablename , $link ); $columns = mysql_num_fields ( $fields ); $fieldnames = array(); $field0=""; $wherestr=""; for ( $i = 0 ; $i < $columns ; $i ++) { $fieldnames[]= mysql_field_name ( $fields , $i ) ; if($i==0) { $field0=mysql_field_name ( $fields , $i ) ; $wherestr.=" ".$fieldnames[$i]." like '%$keyword%'"; }else $wherestr.=" or ".$fieldnames[$i]." like '%$keyword%'"; } $sql="select $field0 from $tablename where ".$wherestr." limit 0,1"; $result = mysql_query($sql); if( $result && $row = mysql_fetch_array($result)) { $field0ret=$row[$field0]; echo "<font color=red><b>success sql=</b>".$sql."</font><br>"; echo "result ".$field0."=".$field0ret."<br>"; flush(); } } mysql_close($link); }//searchdb } ?> 

class searchdb
Introduction and Scope
This class will help you to find a keyword in your database ,no matter in which table.

The search result will show you which tables have the keywords,and show you one sql sentence to get the showing result.

Attributes 
private $dbserver;

private $dbuser;

private $dbpass;

private $dbname;

 

Methods
public function searchdb($keyword);

     find which table have the data of the keyword..

How to use
include "class.searchdb.php";

$dbserver="127.0.0.1";

$dbuser="root";

$dbpass="H8lq$#inay8";

$dbname="nangua";

$sdb = new searchdb($dbserver,$dbuser,$dbpass,$dbname);

$sdb->searchdb('zengwenjie');//input the keyword you want to search in the database

 

 Example of Result
It might be return many result,every result include one sql sentence and the value of first field.

Example:

success sql=select uid from forum_members where uid like '%zengwenjie%' or username like '%zengwenjie%' or password like '%zengwenjie%' or secques like '%zengwenjie%' or gender like '%zengwenjie%' or adminid like '%zengwenjie%' or groupid like '%zengwenjie%' or groupexpiry like '%zengwenjie%' or extgroupids like '%zengwenjie%' or regip like '%zengwenjie%' or regdate like '%zengwenjie%' or lastip like '%zengwenjie%' or lastvisit like '%zengwenjie%' or lastactivity like '%zengwenjie%' or lastpost like '%zengwenjie%' or posts like '%zengwenjie%' or digestposts like '%zengwenjie%' or oltime like '%zengwenjie%' or pageviews like '%zengwenjie%' or credits like '%zengwenjie%' or extcredits1 like '%zengwenjie%' or extcredits2 like '%zengwenjie%' or extcredits3 like '%zengwenjie%' or extcredits4 like '%zengwenjie%' or extcredits5 like '%zengwenjie%' or extcredits6 like '%zengwenjie%' or extcredits7 like '%zengwenjie%' or extcredits8 like '%zengwenjie%' or email like '%zengwenjie%' or bday like '%zengwenjie%' or sigstatus like '%zengwenjie%' or tpp like '%zengwenjie%' or ppp like '%zengwenjie%' or styleid like '%zengwenjie%' or dateformat like '%zengwenjie%' or timeformat like '%zengwenjie%' or pmsound like '%zengwenjie%' or showemail like '%zengwenjie%' or newsletter like '%zengwenjie%' or invisible like '%zengwenjie%' or timeoffset like '%zengwenjie%' or newpm like '%zengwenjie%' or accessmasks like '%zengwenjie%' or editormode like '%zengwenjie%' or customshow like '%zengwenjie%' or xspacestatus like '%zengwenjie%' or customaddfeed like '%zengwenjie%' limit 0,1

result uid=3395

success sql=select order_id from mall_order_info where order_id like '%zengwenjie%' or order_sn like '%zengwenjie%' or user_id like '%zengwenjie%' or order_status like '%zengwenjie%' or shipping_status like '%zengwenjie%' or pay_status like '%zengwenjie%' or consignee like '%zengwenjie%' or country like '%zengwenjie%' or province like '%zengwenjie%' or city like '%zengwenjie%' or district like '%zengwenjie%' or address like '%zengwenjie%' or zipcode like '%zengwenjie%' or tel like '%zengwenjie%' or mobile like '%zengwenjie%' or email like '%zengwenjie%' or best_time like '%zengwenjie%' or sign_building like '%zengwenjie%' or postscript like '%zengwenjie%' or shipping_id like '%zengwenjie%' or shipping_name like '%zengwenjie%' or pay_id like '%zengwenjie%' or pay_name like '%zengwenjie%' or how_oos like '%zengwenjie%' or how_surplus like '%zengwenjie%' or pack_name like '%zengwenjie%' or card_name like '%zengwenjie%' or card_message like '%zengwenjie%' or inv_payee like '%zengwenjie%' or inv_content like '%zengwenjie%' or goods_amount like '%zengwenjie%' or shipping_fee like '%zengwenjie%' or insure_fee like '%zengwenjie%' or pay_fee like '%zengwenjie%' or pack_fee like '%zengwenjie%' or card_fee like '%zengwenjie%' or money_paid like '%zengwenjie%' or surplus like '%zengwenjie%' or integral like '%zengwenjie%' or integral_money like '%zengwenjie%' or bonus like '%zengwenjie%' or order_amount like '%zengwenjie%' or from_ad like '%zengwenjie%' or referer like '%zengwenjie%' or add_time like '%zengwenjie%' or confirm_time like '%zengwenjie%' or pay_time like '%zengwenjie%' or shipping_time like '%zengwenjie%' or pack_id like '%zengwenjie%' or card_id like '%zengwenjie%' or bonus_id like '%zengwenjie%' or invoice_no like '%zengwenjie%' or extension_code like '%zengwenjie%' or extension_id like '%zengwenjie%' or to_buyer like '%zengwenjie%' or pay_note like '%zengwenjie%' or agency_id like '%zengwenjie%' or shop_id like '%zengwenjie%' or inv_type like '%zengwenjie%' or tax like '%zengwenjie%' or is_separate like '%zengwenjie%' or parent_id like '%zengwenjie%' or discount like '%zengwenjie%' limit 0,1

result order_id=551

 

 

你可能感兴趣的:(search one keyword from all tables;)