RE: [PHP-DB] show tables

From: Date: Tue, 28 Jun 2005 14:29:47 +0000
Subject: RE: [PHP-DB] show tables
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-39814@lists.php.net to get a copy of this message
damn hotmail <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> maybe this will look better bastien
From: "Bastien Koert" <bastien_k@hotmail.com> To: blackwaterdev@gmail.com, php-db@lists.php.net Subject: RE: [PHP-DB] show tables Date: Tue, 28 Jun 2005 10:26:41 -0400 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@gmail.com> Reply-To: blackwater dev <blackwaterdev@gmail.com> To: php-db@lists.php.net Subject: [PHP-DB] 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


« previous php.db (#39814) next »