I am looking for a way to identify mysql row fields in perl, similar to php. With the following perl code, when I modify it for another table with different fields, I have to re-count the fields. With the php, I just have to comment out unused fields or add new ones, because they are identified by name not number.
perl
php
Thanks for suggestions
Mike
perl
Code:
$dsn = "dbi:mysql:database";
$dbh = DBI->connect($dsn,'user','password!');
$data = $dbh->selectall_arrayref("SELECT * FROM table") or die "SQL error";
$records = @{$data};
for($x=0;$x<$records;$x++){
$id = $data -> [$x][0];
$first = $data -> [$x][1];
$middle = $data -> [$x][2];
$name = $data -> [$x][3];
php
Code:
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$result = mysql_query("SELECT * FROM table") or die(mysql_error());
$row = mysql_fetch_array($result);
$id = $row['id'];
$first = $row['first'];
$middle = $row['middle'];
$name = $row['name'];
Thanks for suggestions
Mike