connect_errno) { printf("Can't connect to mysql server\n", $mysqli->connect_error); exit(); } $tables = array(); $resTables = $mysqli->query('SHOW TABLES'); while ($table = $resTables->fetch_assoc()) { $tables[] = $table['Tables_in_'.strtolower($database)]; } $resTables->close(); $rowHeading = ($queryType=='replace') ? 'Replacing \''.$search.'\' with \''.$replace.'\' in \''.$database."'\n\nSTATUS | ROWS AFFECTED | TABLE/FIELD (+ERROR)\n" : 'Searching for \''.$search.'\' in \''.$database."'\n\nSTATUS | ROWS CONTAINING | TABLE/FIELD (+ERROR)\n"; $output = $rowHeading; foreach($tables as $table) { if (in_array($table, $tablesNotChange)) { continue; } $resFields = $mysqli->query('SHOW FIELDS FROM '.$table); foreach($resFields as $fieldData) { $field = $fieldData['Field']; $type = $fieldData['Type']; $numSymb = strpos($type, '('); if ($numSymb !== false) { $type = substr($type, 0, $numSymb); } if (!in_array(strtolower($type), $columnTypes)) { continue; } $handle = $table.'_'.$field; if($queryType=='replace') { $sqlColumn = 'UPDATE '.$table.' SET '.$field.' = REPLACE('.$field.',\''.$search.'\',\''.$replace.'\')'; } else { $sqlColumn = 'SELECT * FROM '.$table.' WHERE '.$field.' LIKE(\'%'.$search.'%\')'; } $result = $mysqli->query( $sqlColumn ); $rowsCount = $mysqli->affected_rows; $error = $mysqli->error; if ($showAllTableColumns || $rowsCount > 0) { $output .= ($result) ? 'OK ' : '-- '; $output .= ($rowsCount>0) ? ''.$rowsCount.' ' : ''.$rowsCount.' '; $fieldName = '`'.$table.'`.`'.$field.'`'; $output .= $fieldName; $erTab = str_repeat(' ', (60-strlen($fieldName)) ); $output .= ($error) ? $erTab.'(ERROR: '.$error.')' : ''; if ($showQuery) { $output .= ' '.$sqlColumn; } $output .= "\n"; } } $resFields->close(); } echo $output."\n";