RE: show tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This works for me, note not bulletproof

<html><body>
<?

if (!isset($_POST['submit']))
{
 show_form();
 die();
}


$col = strtolower(@$_POST['col_name']);

$sql = "show tables";
$result = connect($sql);
while ($rows = mysql_fetch_array($result))
{

 $table =  $rows[0];
 $sql2 = "show columns from $table";
 $result2 = connect($sql2);

 echo "Searching for $col in table: $table<br>";

 if ($result2)
 {
   while ($rows2 = mysql_fetch_array($result2))
   {
     if ($col == strtolower($rows2[0]))
     {
       echo "<b>Table matching $col: $table</b><br>";
     }
   }
 }
}


function connect($sql)
{
	$username   = "root";
	$pwd        = "rum31nt";
	$host       = "localhost";
	$dbname     = "test";

	//echo "commnecing connection to local db<br>";

	if (!($conn=mysql_connect($host, $username, $pwd)))  {
	    printf("error connecting to DB");
	    exit();
	}
	$db2=mysql_select_db($dbname,$conn);

	$result = mysql_query($sql);
	if ($result){
		return $result;
	}else{
	  $error = mysql_error();
		echo "Can't complete query because $error";
		die();
	}

}

function show_form()
{
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>
     Input Column Name:<input type='text' name='col_name' size='15'>
     <br /><input type='submit' name='submit' value='submit'>
     <form>";

}
?>
</body></html>


bastien

From: blackwater dev <blackwaterdev@xxxxxxxxx>
Reply-To: blackwater dev <blackwaterdev@xxxxxxxxx>
To: php-db@xxxxxxxxxxxxx
Subject:  show tables
Date: Tue, 28 Jun 2005 09:43:28 -0400

How can I run a query to find all of the tables in a db with a certain
columname?

Thanks!

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux