PDA

View Full Version : Mysql:repare: Not defined in Mysql and not autoloadable (last try prepare)


oskeywoskey
07-27-2005, 04:43 AM
Can anyone help me with why am I getting this error:

Mysql:repare: Not defined in Mysql and not autoloadable (last try prepare)

I'm new to perl and mysql and I created a simple perl program to insert some hard-coded values into a

database. Note, below is just a small part of my program, the rest of my program works fine. It was

only when I tried using the insert that I got this message.


use Mysql;
use DBI;

use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use URI::Heuristic;

#My connect
$DBHOST="localhost";
$DBNAME="database01";
$DBUSER="root";
$DBPASS="";

$db = Mysql->connect($DBHOST, $DBNAME, $DBUSER, $DBPASS);
$db->selectdb($DBNAME);

my $put_in_db = $db->prepare('INSERT INTO test_table (name, hair_color, eye_color) VALUES ("Timothy",

"Blonde", "Green")');
$put_in_db->execute();


I've installed the dbi using the perl package manager and I've tested some other code that instead of

using "INSERT", it uses a "SELECT" statement which was successful in retrieving info. from an existing

database. So it seems that perl isn't having a problem communicating with the database, or is there

still a problem??? I need some serious HELP with this one!! This is driving me nuts!!

shyam
07-27-2005, 07:53 AM
my $put_in_db = $db->prepare('INSERT INTO test_table (name, hair_color, eye_color) VALUES (?,?,?)');
$put_in_db->execute("Timothy", "Blonde", "Green");

FishMonger
07-27-2005, 06:08 PM
Why are you using both modules (Mysql and DBI)? All you need is the DBI module.

use DBI;

#My connect
$DBHOST="localhost";
$DBPORT = 3306; # This is not required, but I added it anyway.
$DBNAME="database01";
$DBUSER="root";
$DBPASS="";

my $db = DBI->connect( "DBI:mysql:$DBNAME:$DBHOST:$DBPORT", $DBUSER, $DBPASS, {'RaiseError' => 1, 'PrintError' => 0} )
or die "Failed to Connect to $DBNAME on $DBHOST:\n\t$DBI::errstr\n";

my $put_in_db = $db->prepare('INSERT INTO test_table (name, hair_color, eye_color) VALUES ("Timothy", "Blonde", "Green")');
$put_in_db->execute();
If you're doing multiple inserts, such as in a loop, or the values need to be determined at a later point, use the method for the prepare and execute statements that shyam shows.