Jump to content

php with MySQL - memory problem


dumdumsareyum

Recommended Posts

I wrote a little program to search all the tables in a particular database for a value. It was working just fine, but when I tried to search a very large database (73 large tables) it would return results for about 8 tables and then give an out of memory error. I tried using "mysql_free_result($result)"  (which I have commented out in the posted code), but that gave me an error saying "supplied argument is not a valid mysql result resource." Help please?

 

<?php
/*Program:  mysql_send.php
*Desc:     PHP program that searches all tables in a database
*          MySQL server and displays the results.
*/
echo "<html>
      <head><title>SQL Query Sender</title></head>
      <body>";

$host="localhost";
$user="root";
$password="";
$dbname = "PetCatalog";

$cxn = mysqli_connect($host,$user,$password,
                        $dbname)  or die("Could not connect to server");

$query = "SHOW TABLES";

$result = mysqli_query($cxn, $query);

$rownum = 0;
       
      while( $row = mysqli_fetch_row($result))
{
        	foreach($row as $i =>$value)
        	{
         	 $tablenames[$rownum]= $value;
	$rownum++;
        	}
        }

$counter = 0;

$searchstring = "Pegasus";
$foundcount = 0;

$size = sizeof($tablenames);

echo "$size tables found.";

do
{
  
  $query = "SELECT * FROM $tablenames[$counter]";
  
  $result = mysqli_query($cxn, $query)  or die ("could not execute         

      query");
  $rownum = 1;

echo "<h3>Results from table '$tablenames[$counter]'</h3>";

while($row = mysqli_fetch_assoc($result))
  {
        
        foreach($row as $column => $value)
        {
          $searcharray[$rownum][$column] = $value;

    			if ($value == $searchstring)
		{
		echo "$searchstring found, column $column, 
		row $rownum,						

		table {$tablenames[$counter]}";
		$foundcount++;
		}
}
$rownum++;	
   }
$counter++;
//mysql_free_result($result);
}
while($counter < sizeof($tablenames));


echo "$searchstring was found $foundcount time(s)";
?>

</body></html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.