Need Help! PHP to Perl

They have: 103 posts

Joined: Apr 1999

Unfortunately, Perl isn't that kind with regards to databasing. You'll probably need to use DBI. There just isn't a mysql_query() command in Perl. That's partially the reason I switched over to PHP.

------------------
Gil Hildebrand, Jr.
Senior Web Developer, 4atcost.com

Gil Hildebrand, Jr.
Internet Consultant
New Orleans, LA

They have: 5,633 posts

Joined: Jan 1970

The nice thing about Perl's DBI is that its database independent (hence the name DBI), so it will work across many databases by changing a single line of code (assuming your not using any database specific commands, which in many cases, you aren't).

DBI is actually nicer with databases then PHP's current method, but they are already some PHP DBI type modules that will do the same things as Perl's.

-Marc

They have: 12 posts

Joined: Dec 1999

Could someone convert the following PHP code into perl? I use this for dumping from MySQL and loading from DBM format. I use it to copy mysql records to/from my home computer and webhost, unfortunately my host uses an older version of DBM for the PHP.

Thanks in advance.

Here is my PHP code for dumping MySQL to DBM:

// --- open input file
$sql = "SELECT * FROM $rm_tbl ORDER BY rcode ASC";
$result = mysql_query($sql,$db);

if ($result) {

// --- open output file
if ($dbm_id = dbmopen($rm_dbdump.$rm_tbl,"n")) {

$i = 0;
while ($myrow = mysql_fetch_array($result)) {

// --- increment record key
$i++;

// --- serialize record
$arec = addslashes(serialize($myrow));

// --- write a record
$isok = dbminsert($dbm_id, $i, $arec);

}

// --- close dbm file
$isok = dbmclose($dbm_id);

echo "$i Records dumped to ".$rm_datadump.$rm_tbl.".db!";

} else

echo "Unable to open output file!";
}

// --- END DUMP

Here is my PHP Code for Uploading from DBM to MySQL:

// --- open input file
if ($dbm_id = dbmopen($rm_dbload.$rm_tbl,"r")) {

for ($i=1;dbmexists($dbm_id,$i);$i++) {

// --- retrieve the record pointed to by $nkey
$arec = dbmfetch($dbm_id, $i);
$myrow = unserialize($arec);

// --- extract array values to non-array variables
extract($myrow, EXTR_PREFIX_ALL, "q");

$q_rname = addslashes($myrow["rname"]);
$q_rdesc = addslashes($myrow["rdesc"]);
$q_instru = addslashes($myrow["instru"]);

// --- insert record into table
$sql = "INSERT INTO $rm_tbl (country,rname,rcateg,rdesc,preptime,instru,ownerid,stime,erase) VALUES ('$q_country','$q_rname','$q_rcateg','$q_rdesc','$q_preptime','$q_instru','$q_ownerid','$q_stime',$q_erase)";
$result = mysql_query($sql,$db) or mysql_die();
}

// --- close dbm file
$isok = dbmclose($dbm_id);

echo ($i-1)." Records loaded from ".$rm_dataload.$rm_tbl.".db!";

} else

echo "Unable to open input file!";

// --- END LOAD

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.