The manual says:

<?php
mysql_connect("host");
$result = mysql_list_tables("wisconsin");
for ($i = 0; $i < mysql_num_rows($result); $i++) {
    $tb_names[$i] = mysql_tablename($result, $i);
    echo $tb_names[$i] . "<BR>";
}
?>

To paraphrase, just use mysql_list_tables() to get a table list in a result set, then go through the result set to see if the named table exists.

But wouldn't it be easier to create the tables in the first place?

cheers,

Travis


John Taylor-Johnston wrote:
How can I check if a table exists in a mysql db. If it table does not exist, then,

$news = mysql_query($sql_create);

else

$news = mysql_query($sql);

Not sure I know where to start?


-----snip-------- $server = "localhost"; $user = "user1"; $pass = "****"; $db="user1table"; $table="comments";

$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);

$sql = 'SELECT * FROM '.$table.' WHERE MATCH (username) AGAINST 
(\''.stripslashes($searchenquiry).'\' IN BOOLEAN MODE) ORDER BY id asc;';

$sql_create = "CREATE TABLE ".$table." (
   id int(11) NOT NULL auto_increment,
   username varchar(100) NOT NULL,
   comment text,
   PRIMARY KEY (id)
);




Sorry, I'm not even sure if this is a php thing as much as it is also mysql.

-
John


-- Travis Low <mailto:[EMAIL PROTECTED]> <http://www.dawnstar.com>

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



Reply via email to