Jump to content

Recommended Posts

Posted

I've managed to connect to the database, but can't issue a query (and subsequently see its result). Here is the script:

 

-----

 

#! /usr/bin/perl

 

# carp

print "Content-type: text/html\n\n";

 

# declare mod usage

use DBI;

 

# connect to mysql db

$dbh = DBI->connect("DBI:mysql:$database:localhost", $user, $passwd);

print "connected.<br>";

 

# build query

$query = "select * from $table where 1";

print "query built.<br>";

 

# prep due to multirow result

$cursor = $dbh->prepare($query);

print "query prepared.<br>";

 

# commented out because above doesn't work

#$cursor->execute();

#print "query executed.<br>";

 

# clean up

$cursor->finish();

$dbh->disconnect();

 

----

 

and the output I get is:

 

"connected.

query built."

 

Apparently there is a problem with the prepare() statement, but I can't see anything wrong with it. Any help is appreciated.

Posted

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. =)

Posted

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 my script from the command line and grab the error to discover that.

Posted

Yes that is the step we all miss the most

When you create a user, you may have many databases

so you need to select the proper database to add the user to.

 

Thank you for the followup.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...