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
https://forums.phpfreaks.com/topic/53807-php-with-mysql-memory-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.