Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4
¿Alguien me podría apoyar, por favor? Estoy tratando de crear un usuario y contraseña (en MD5) en una tabla de MySQL.
Crear.pl:
Using perl Syntax Highlighting
- use DBI;
- my $nombre = "test8";
- my $passwd = "123456";
- $passwd = unix_md5_crypt $passwd;
- my $dsn = "DBI:mysql:database=basetest;host=127.0.0.1";
- my $dbh = DBI->connect($dsn, "usertest", "123456");
- my $sql = $dbh->prepare('INSERT INTO users VALUES (?,?)');
- my $res = $dbh->selectcol_arrayref($sql, undef, $nombre, $passwd);
- $res->execute() or die $DBI::errstr;
- $yes->finish();
Coloreado en 0.004 segundos, usando GeSHi 1.0.8.4
Si crea el usuario
Using sql Syntax Highlighting
- SELECT * FROM users;
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
Using text Syntax Highlighting
| test7 | $1$5QoNYyCe$G9Io8rhSbZ8m0x/zJDKlW/"
pero me sale este error:
Using text Syntax Highlighting
Uncaught exception from user code:
Statement has no result columns to bind (perhaps you need to call execute first) at /usr/lib/perl5/DBD/mysql.pm line 809.
DBD::mysql::st::__ANON__('DBI::st=HASH(0x1278af0)', 1, 'SCALAR(0x12787c0)') called at /usr/lib/perl5/DBI.pm line 1685
DBD::_::db::selectcol_arrayref('DBI::db=HASH(0xff3960)', 'DBI::st=HASH(0x12789b8)', undef, 'test8', '$1$nYODOWtt$2JKWqDnZNWbkvU4L9wHFT0') called at ./pass.pl line 17
Statement has no result columns to bind (perhaps you need to call execute first) at /usr/lib/perl5/DBD/mysql.pm line 809.
DBD::mysql::st::__ANON__('DBI::st=HASH(0x1278af0)', 1, 'SCALAR(0x12787c0)') called at /usr/lib/perl5/DBI.pm line 1685
DBD::_::db::selectcol_arrayref('DBI::db=HASH(0xff3960)', 'DBI::st=HASH(0x12789b8)', undef, 'test8', '$1$nYODOWtt$2JKWqDnZNWbkvU4L9wHFT0') called at ./pass.pl line 17
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4
Y cuando quiero comparar si existe me da 0.
Verificar.pl
Using perl Syntax Highlighting
- use DBI;
- my $nombre = "test8";
- my $passwd = "123456";
- $passwd = unix_md5_crypt $passwd;
- my $dsn = "DBI:mysql:database=basetest;host=127.0.0.1";
- my $dbh = DBI->connect($dsn, "usertest", "123456");
- my $sql = $dbh->prepare('select count(*) from users where username = ? and password = ?');
- my $res = $dbh->selectcol_arrayref($sql, undef, $nombre, $passwd);
- if ($res->[0] == 1) {
- print "Existe\n";
- }
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
Ya lo tengo con PHP
Using php Syntax Highlighting
- $sql = "SELECT * FROM users
- WHERE username = "$user"
- AND password = '".md5( $password )."'";
Coloreado en 0.031 segundos, usando GeSHi 1.0.8.4
Pero la verdad me gusta más Perl
Gracias y saludos.