You are here: Re: Automatically detecting tables in a db « PHP Programming Language « IT news, forums, messages
Re: Automatically detecting tables in a db

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация