View Full Version : Help
Billybob54
11-22-01, 04:02 AM
I am using perl in a cgi script to connect to the database and make a table, I am using the following code:
$dbh = DBI->connect("DBI:mysql:$database:$db_server", $user, $password);
$statement = "CREATE TABLE TableName (table collom names)";
$sth = $dbh->prepare($statement)
or die "Couldn't prepare the query: $sth->errstr";
$rv = $sth->execute
or die "Couldn't execute query: $dbh->errstr";
I says in the error message "Can't call method "prepare" on an undefined value" Can anyone tell me what the problem is?
sophiespo
11-22-01, 05:38 AM
Did you mean to leave the "; off the end of the following line?
$statement = "CREATE TABLE TableName (table collom names)
I dont know much about php but I do a LOT of programming (including CGI) and if you start the string with a " you should end it with ";
youre calling prepare on $statement and it says its undefined? That might be why.
sophie
Billybob54
11-22-01, 05:51 AM
In my script there is a "; at the end of it so that can't be the problem. Also that script is CGI, I got it out of a CGI book. If you know of a different way to connect and change a MySQL Database using CGI let me know and I will try it.
Maybe you should quote the prepare statement.
$sth = $dbh->prepare(qq{$statement}) or die "Couldn't prepare the query: $sth->errstr";
You could also try putting the SQL statement inside the prepare statement instead of passing it to a variable (since it's saying the variable is undefined) to see if it takes the statement that way.
$sth = $dbh->prepare(qq{CREATE TABLE TableName (table collom names)}) or die "Couldn't prepare the query: $sth->errstr";
Hope this helps! :)
~bud
Billybob54
11-22-01, 09:05 PM
I tried your things and it still does not work.
Billybob54
11-23-01, 09:00 PM
I got it to work. It did not work because powweb said i could use pluto.powweb.com or my domain name as the host, but only my domain name worked. I was using pluto.powweb.com, and that is why i got the error
vBulletin v3.6.0, Copyright ©2000-2010, Jelsoft Enterprises Ltd.