Perl And Mysql

liunx

Guest
I've managed to connect to the database, but can't issue a query (and subsequently see its result). Here is the script:<br /><br />-----<br /><br />#! /usr/bin/perl<br /><br /># carp<br />print "Content-type: text/html\n\n";<br /><br /># declare mod usage<br />use DBI;<br /><br /># connect to mysql db<br />$dbh = DBI->connect("DBI:mysql:$database:localhost", $user, $passwd);<br />print "connected.<br>";<br /><br /># build query<br />$query = "select * from $table where 1";<br />print "query built.<br>";<br /><br /># prep due to multirow result<br />$cursor = $dbh->prepare($query);<br />print "query prepared.<br>";<br /><br /># commented out because above doesn't work<br />#$cursor->execute();<br />#print "query executed.<br>";<br /><br /># clean up<br />$cursor->finish();<br />$dbh->disconnect();<br /><br />----<br /><br />and the output I get is:<br /><br />"connected.<br />query built."<br /><br />Apparently there is a problem with the prepare() statement, but I can't see anything wrong with it. Any help is appreciated.<!--content-->
This is really a script issue so I'm going to move it to the script section. We have some perl coders around here that are really good so that should help them to find ya. =)<!--content-->
I found out what the problem was. I created a database and a user, but I didn't add that use to the database. Didn't realize I had to do that, I figured adding the user would take care of that. Had to write a script that would run <i>my</i> script from the command line and grab the error to discover that.<!--content-->
Yes that is the step we all miss the most<br />When you create a user, you may have many databases<br />so you need to select the proper database to add the user to.<br /><br />Thank you for the followup.<!--content-->
 
Back
Top