0

I am trying to retrieve a string which is in whole of database without mentioning name of table and column, but my PHP code shows an error

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean

Can anyone help me where am I going wrong?

<?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!';


?>
3
  • I'm pretty sure that the SHOW TABLES is going to return true/false instead of a query handle because you're not executing a SELECT command. Try getting the table names with a SELECT from information_schema.tables instead. Commented Oct 22, 2014 at 12:16
  • These links might helpSO duplicate question - Microsoft Search for a string in all tables of SQL Server Database - Another duplicate question on SO Commented Oct 22, 2014 at 12:20
  • $query gives me the select script dynamicaly example:( 1.SELECT * From artworks WHERE ImageName = "test" 2.SELECT * From artworks WHERE Title = "test" 3.SELECT * From artworks WHERE size = "test") Commented Oct 22, 2014 at 12:27

1 Answer 1

1

The result in $HHHH is obiously not valid. If you echo the $query, you can see what happens. Probably something not right there. But because we don't know the value of $table, I have no clue what could be wrong.

Piece of advice: mysql is a little outdated. When you use MySQL with PHP the advice is MySQLi: read here: http://php.net/manual/en/function.mysql-fetch-row.php

Sign up to request clarification or add additional context in comments.

1 Comment

look at my comment above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.