I need to prepare a perl script that matches an insert php script I already have, can anyone help me?
use username_db;
create table customer
(cust_num int(4) NOT NULL
company char(25),
cust_rep int(3),
credit_limit int(5));
//then i have four more tables and the following
/*---------------------*/
insert into customer values
(2111, 'JCP Inc.', 103, 50000)
insert into customer values
(2102, 'First Corp.', 101, 65000)
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
"user", "pass",
{'RaiseError' => 1,
'AutoCommit' => 1,});
my $create_sql = qq~create table customer (cust_num int(4) NOT NULL company char(25), cust_rep int(3), credit_limit int(5))~;
my $crv = $dbh->do($create_sql);
$insert_sql = qq~insert into customer values (?, ?, ?, ?)~;
my $sth = $dbh->prepare($insert_sql);
my $irv = $sth->execute(2111, 'JCP Inc.', 103, 50000);
$irv = $sth->execute(2102, 'First Corp.', 101, 65000);
That's untested and likely to contain errors but it will give you something to start with. Make sure you check thoroughly check out the docs for DBI[1] and teh DBD driver for your database (I assumed MySQL in this example).