Current location: Hot Scripts Forums » Programming Languages » Perl » php to perl??


php to perl??

Reply
  #1 (permalink)  
Old 03-08-05, 12:31 PM
mangotext mangotext is offline
Newbie Coder
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Cool php to perl??

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)

//and so on..
can anyone help???
Reply With Quote
  #2 (permalink)  
Old 03-08-05, 10:12 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Something like this should work:

Code:
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).

~Charlie

[1] http://search.cpan.org/~timb/DBI/DBI.pm
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Vs Perl pagetta PHP 1 11-26-04 10:58 AM
Converting from Perl to PHP G-Money Perl 1 07-23-04 04:38 PM
Translate ASP to PHP and PERL POSERA ASP 0 06-12-04 01:12 AM
convert perl code to php phptalk Perl 1 01-15-04 02:06 AM
php visual basic perl cgi - outsource programming to india outsource_india General Advertisements 0 10-28-03 03:21 AM


All times are GMT -5. The time now is 04:03 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.