Tema: Php a Perl
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 15/06/2006, 15:06
QuakEgoD
 
Fecha de Ingreso: mayo-2005
Mensajes: 15
Antigüedad: 19 años, 9 meses
Puntos: 0
Muchas Gracias!! Esteban, entonces la cuestión sería asi:

archivo auto.pm:

Código:
#!/usr/bin/perl -w

package AUTO;

use strict;
use DBI;

my $db_user = "aaa";
my $db_pass = "bbb";
my $host_name = "10.10.10.10:3306";
my $db_name = "base;
# vars
my $q_string = "DBI:mysql:host=$host_name;database=$db_name";
sub connect{
return (DBI->connect ($q_string, $db_user, $db_pass,
{PrintError => 0, RaiseError => 1}));
}

1
y el otro llamado script.pl:

Código:
use AUTO
my($dbh,$sth);

$dbh = AUTO->connect();
$sth = $dbh->prepare('select max(id_tabla)+1 num from tabla') or die("Couldn't prepare statement: " . $dbh->errstr);
$sth->execute() or die("Couldn't execute statement: " . $sth->errstr);

my $maxnum = $sth->fetchrow_array();
$sth->finish;

$sth1-> $dbh->prepare('insert into tabla (id_tabla) values (?)');
$sth1->execute($maxnum) or die("Couldn't execute statement: " . $sth->errstr);
$dbh->disconnect;
exit;