我試圖找回一個字符串,是在整個數據庫的不提表和列的名字,但我的PHP代碼顯示錯誤如何搜索字符串在MySQL數據庫在PHP
警告:
mysql_fetch_row()
期望參數1是資源,布爾值
任何人都可以幫助我,我哪裏會出錯?
<?php
// Setup the associative array for replacing the old string with new string
$replace_array = "test";
$HHHH;
$ffff;
$mysql_link = mysql_connect('localhost:3306', 'tribhuvan', '123456');
if(! $mysql_link) {
die('Could not connect: ' . mysql_error());
}
$mysql_db = mysql_select_db('a_t', $mysql_link);
if(! $mysql_db) {
die('Can\'t select database: ' . mysql_error());
}
// Traverse all tables
$tables_query = 'SHOW TABLES';
$tables_result = mysql_query($tables_query);
while($tables_rows = mysql_fetch_row($tables_result)) {
foreach($tables_rows as $table) {
// Traverse all columns
$columns_query = 'SHOW COLUMNS FROM ' . $table;
$columns_result = mysql_query($columns_query);
while($columns_row = mysql_fetch_assoc($columns_result)) {
$column = $columns_row['Field'];
$type = $columns_row['Type'];
// Process only text-based columns
if(strpos($type, 'char') !== false || strpos($type, 'text') !== false) {
// Process all replacements for the specific column
$query = 'SELECT * From ' . $table .
' WHERE ' . $column . ' = "'.$replace_array.'"';
$HHHH = mysql_query($query);
$ffff = mysql_fetch_row($HHHH);
}
}
}
}
while($queryValues = $ffff) {
foreach($queryValues as $Values) {
echo $Values."<br/>";
}}
mysql_free_result($columns_result);
mysql_free_result($tables_result);
mysql_close($mysql_link);
echo 'Done!';
?>
我很確定'SHOW TABLES'將返回true/false而不是查詢句柄,因爲你不執行'SELECT '命令。嘗試使用'information_schema.tables'中的'SELECT'來代替表名。 – 2014-10-22 12:16:27
這些鏈接可能會幫助[所以重複的問題](http://stackoverflow.com/questions/8435963/how-to-find-a-string-inside-a-entire-database) - [微軟在所有搜索字符串SQL Server數據庫的表](https://gallery.technet.microsoft.com/scriptcenter/c0c57332-8624-48c0-b4c3-5b31fe641c58) - [另一個重複的問題在SO](http://stackoverflow.com/questions/ 13174627/how-to-search-string-from-databases-sql-server/22854200#22854200) – Billy 2014-10-22 12:20:02
$ query給我選擇腳本dynamicaly示例:(1.SELECT *從作品WHERE ImageName =「test」 2.SELECT *從藝術品WHERE標題=「測試」 3.選擇*從藝術品WHERE大小=「測試」) – 3bu1 2014-10-22 12:27:21