in reply to (Ovid) Re: dbi 500 error
in thread dbi 500 error

I have taken your advice into consideration and have come up with my new version(that does not create and errors).
#!/usr/local/bin/perl use CGI qw/:standard/; use DBI; print header, start_html( -title => 'Test ' ), h1( 'Hello world' ), end_html; my $dbh; $dbh = DBI->Connect("DBI:mysql:strossus:localhost","strossus","******* +*"); my $table = $dbh->prepare (qq' CREATE TABLE players (firstname CHAR(20), lasttname CHAR(20), email CHAR(50), player INTEGER NOT NULL,, hitp INTEGER, maxhtipp INTEGER, minatt INTEGER, maxatt INTEGER, exp INTEGER, gold INTEGER)'); $table->execute(); $talbe->finish(); $dbh->disconnect();

Edited 2002-01-17 by Ovid to hide password :(

Replies are listed 'Best First'.
(Ovid) Re(3): dbi 500 error
by Ovid (Cardinal) on Jan 18, 2002 at 03:28 UTC

    I just edited your post to hide your password. Be careful!

    First, like I said, I still wouldn't want to run a CREATE TABLE command through a CGI script. What happens when someone calls your program again? It will try to create a table that already exists. I've never tried to do that, so I can't guess what will happen. I suspect that things will die a horrible death, but no guarantees.

    Second, you should either check all of your DBI calls for success, or add the RaiseError attribute to your connect call. See trs80's response below.

    Last, you'll still want to have a unique, non-indentifying ID for the table.

    CREATE TABLE players ( player_id INTEGER NOT NULL PRIMARY KEY, firstname VARCHAR (20) NOT NULL, lastname VARCHAR (20) NULL, ... more stuff here ... ) CREATE TABLE foo ( foo_id INTEGER NOT NULL PRIMARY KEY, player_id INTEGER NOT NULL REFERENCES players (player_id), stuff VARCHAR(30) NOT NULL )

    Learning databases is a good thing, but be sure to learn them well. It's very easy to do thing wrong. Life is Hell for the programmer who is forced to work with a poorly designed database.

    Update: I just tossed in the other table to show you how things things work. If your database will be simple enough that you only need one table, it's not necessary. If, however, it's going to be complex, you'll want to start learning these design issues.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      i am confused about why i would need the second table