|
Posted by jerry gitomer on 07/01/05 17:24
bissatch@yahoo.co.uk wrote:
> Hi,
>
> Is it possible to write a script that, when provided with a database,
> it will return all the tables names?
>
> I will go onto try and put together a script that will not only output
> the table names but also output the sql code required to CREATE the
> table (i.e. CREATE TABLE example (exampleid auto_increment not null
> primary key integer, name text, email text);) - Is this pretty simple
> to do? Are there any free scripts online that would do this? Cheers
>
> Burnsy
>
Burnsy
Yes! The exact script to list the tables in a database depends
on the database you are using. For example in MySQL the script
would include:
$sql1 = "SHOW TABLES";
$res1 - mysql_query($sql1, $db) or die(ms_err_msg(db,
$mysql_error));
Following is an example of a create table script. Edit it to
use your table column names and characteristics.
$sql2 = "DROP TABLE IF EXISTS mbr";
$res2 = mysql_query($sql2, $db) or die(ms_err_msg($db,
$mysql_error));
$sql3 = "CREATE TABLE mbr (
email varchar(80) NOT NULL,
uname varchar(32) NOT NULL,
password varchar(32) NOT NULL,
refemail varchar(80),
balance int(11) NOT NULL,
mtype char(1) NOT NULL,
zip varchar(11) NOT NULL,
lastvisit varchar(10),
PRIMARY KEY (email))";
$res3 = mysql_query($sql3, $db) or die(ms_err_msg($db,
$mysql_error));
ms_err_msg is a function that displays a caption, the mysql
error, and closes the database.
HTH
Jerry
Navigation:
[Reply to this message]
|