kidd, ¡gracias por contestar! corregí la línea que me dijiste... y el script quedo así
Using perl Syntax Highlighting
#!/usr/bin/perl
use strict
;
use DBI
();
#$data_source="localhost";
#$username="root";
#$password="rootwdp";
my $dbh = DBI
->connect("DBI:mysql:host=localhost;database=iac_database",
"root","rootwdp",
{'RaiseError'=>1
});
my $sth = $dbh->prepare("SELECT * FROM cst_usuario");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref())
{
print "Found a row: id = $ref->{'us_idUsuario'}, name = $ref->{'us_nombre'}, last name = $ref->{'us_apellido'}\n";
}
$sth->finish();
$dbh->disconnect();Coloreado en 0.001 segundos, usando
GeSHi 1.0.8.4
¡Y me sale el mismo error!
- Código: Seleccionar todo
DBI connect('host=localhost;database=iac_database','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at base3.pl line 9
¿Qué crees que pueda ser?
Estuve leyendo el tutorial que me recomendaste... pero me sale errores también. Mira, éste sería el código de ConectarDB.pm
Using perl Syntax Highlighting
#!/usr/bin/perl -w
package ConectarDB
;
use strict
;
use DBI
;
my $db_user = "root";
my $db_pass = "....";
my $host_name = "localhost";
my $db_pass = "......";
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;Coloreado en 0.001 segundos, usando
GeSHi 1.0.8.4
y aun así me sale error cuando lo llamo de otro script... me sale este error
- Código: Seleccionar todo
"my" variable $db_pass masks earlier declaration in same scope at ConectarDB.pm line 11.
Global symbol "$db_name" requires explicit package name at ConectarDB.pm line 13.
Compilation failed in require at base4.pl line 3.
BEGIN failed--compilation aborted at base4.pl line 3.
Te agradecería millón toda la ayuda posible que me puedas brindar.