RE: [PHP] copying the structure of a blank table in mysql
| From: | John Holmes | Date: | Mon, 24 Jun 2002 08:57:29 +0000 |
| Subject: | RE: [PHP] copying the structure of a blank table in mysql | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-103554@lists.php.net to get a copy of this message | ||
> Anyone have a link (or the code) to copy the structure of a blank
table
> to a new table using mysql?
<?
function change_table_name($old_name, $new_name)
{
$result = mysql_query("show create table $old_name");
$create = mysql_result($result,0,1);
str_replace("TABLE
$old_name","TABLE
$new_name",$create);
$result = mysql_query($create);
return;
}
?>
Untested, add in some error checking and validate the $old and $new
names, and adapt to your needs...
---John Holmes...