in reply to How to query mysql database schema with DBI

SHOW CREATE TABLE responses

There are other ways using DBI, but that's the MySQL way. I strongly suggest you read both the DBI documentation as well as the MySQL documentation.

Furthermore, I wouldn't create my schema within a CGI script. Your schema should exist separate from your web application, for a whole host of reasons.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: How to query mysql database schema with DBI
by punch_card_don (Curate) on Oct 04, 2004 at 20:50 UTC
    Thanks. Uh, I hate to sound thick, but would that be used like this:
    $dbh = DBI->connect($db_datasource, $db_user_name, $db_password) or di +e("Could not connect!"); $sql= "SHOW CREATE TABLE responses"; my $command = $dbh->prepare($sql) or die("Could not prepare!"); $command->execute() or die("Could not create!"); while ( my @row = $command->fetchrow_array( ) ) { print "@row\n"; }
      As for creating via a cgi program, I'm just playing right now. It would never be part of a running program. Just a script that's run once to create the schema, then removed.

      But I'm open to better suggestions if you have one!

        My preferred method of creating tables is to put the create statement in a text file with a meaningful name, such as mytable_schema_2004_10_04.sql

        Then from the unix command line you can just:

        cat mytable_schema.sql |mysql -u [user] -p
        This way, you have a copy of the original schema.

        If it doesnt create correctly, you can modify the file easily enough to fix the problem.

        If you ever make changes with ALTER, the original schema is still available.

        Also, if you ever want to make an identical table, you already have the schema, or if you want to make a similar table, you can modify a copy of this file.

        Yeah, in a lot of ways its like doing it from a script that you can run over and over, but doing it from a script is more complicated and less portable.

        Wht's wrong with using the mysql client program? Or, MySQL AB has a number of graphical clients you can use.

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Nevermind - figfured it out. fetchrow_array works. Probably a more elegant way though...