Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Perl Mysql

by PyroX (Pilgrim)
on Sep 21, 2001 at 22:49 UTC ( [id://113965]=perlquestion: print w/replies, xml ) Need Help??

PyroX has asked for the wisdom of the Perl Monks concerning the following question:

Alright, here is my code:
$db=Mysql->connect($host, $database, $user, $password); $db->selectdb($database); $run="drop table $idip"; my $sth = $db->prepare($run); $sth->execute();

I wrote it just like I read in a tutorial somewhere, but it is not functional, saying:
Mysql::prepare: Not defined in Mysql and not autoloadable (last try prepare) at /usr/bin/snmpwdr line 222

Any ideas, anyone PLEASE...

I intalled both the DBD, DBI, and the Mysql perl module. This is so frustrating.

Replies are listed 'Best First'.
Re: Perl Mysql
by perrin (Chancellor) on Sep 21, 2001 at 22:58 UTC
    The Mysql module is not DBI. It looks like you're trying to combine the Mysql module's interface with the DBI interface. You should pick one or the other and check the documentation for it. (I suggest avoiding the Mysql module, since it seems out-of-date and DBI is more general.) There's lots of DBI info on PerlMonks and DBI comes with extensive documentation.
Re: Perl Mysql
by MrCromeDome (Deacon) on Sep 21, 2001 at 23:08 UTC
    I would highly recommend using DBI for database access. You'll easily be able to switch between DBMSes at a later time should the need arise (and, IMHO, it's extremely easy to use).

    Should you have any questions, let us know :)

    MrCromeDome

Re: Perl Mysql
by PyroX (Pilgrim) on Sep 21, 2001 at 23:07 UTC
    So , this is going to sound ill-informed, or under educated, but,,,

    I don't have to use Mysql to connect to Mysql Databases?
    Which has prepare() in it?
    Can you show me an example of code to run a basic query on a mysql database? I just will be doing 3 things, dropping a table, adding a table, and then inserting into a table.

    I have such a headache, switching between csh, perl, and php all day on this...

    Thanks in advance for helping me.
      Providing that you have DBI and DBD::MYSQL installed. . .

      Connecting to a database:

      my $database = DBI->connect("DBI:mysql:database_name,'user','pw') or die "Could not connect to database: " . DBI->errstr;
      To drop a table:
      my $script = "DROP TABLE your_tablename "; my $sql = $database->prepare_cached($script) || die "Couldn't prepare SQL: " . $database->errstr; $sql->execute() || die "Can't execute SQL: " . $database->errstr; $sql->finish();
      You should really read the documentation on DBI. It's much more complete than this. But this should get you started.

      Hope this helps!
      MrCromeDome

Re: Perl Mysql
by PyroX (Pilgrim) on Sep 21, 2001 at 23:21 UTC
    Thanks! I just needed something to look at to get a fell of whats its goint o be like. I will RTFM, but like to see exactly how it works, at least now I know to use DBI. Thanks Again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://113965]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (9)
As of 2024-04-23 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found