Hi monkers. Im facing a strange issue, i have done a piece of code to get connected to a db, select some values passed from a HTML form and use this value has a value of the query. MY db its on local and im using DBD::Mysql driver to get connected to the database. When i do the query using the file connection.cgi (with a select : select * from db) it returns me a lot of blank results, falling in a infinite loop of dead that kill my machine. I dunno what da hell im going bad, my table only have 2 records and perl see that 2 records and then populate my HTML-results page with
BreakLines.... Updated: i doesnt saw this perl script flush all the data of the query to ha hash, this make my computer hangs up, but if i print the output to the HTML, it prints me breaklines to the end of times. This its mi code
#!"C:\xampp\perl\bin\perl.exe" use CGI qw(:all); use DBI; use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; #Datos de la conexión $db="db_jo151"; $host="localhost"; $port="3306"; $userid="db4_fabrik"; $passwd="secret!"; #Recibimos los datos del formulario @campos = split(/\&/,$ENV{'QUERY_STRING'}); foreach $valor (@campos) { ($nombre_variable, $dato) = split(/=/,$valor); print "$nombre_variable = $dato\n"; } # Realizamos la conexión a la base de datos $dbh = DBI->connect("DBI:mysql:database=$db;host=$host", $userid, $pas +swd); #Sentencia SQL $query = qq(select * from joomladb_estados where est_matricula like '% +$dato'); print "<h2>la query es -->$query</h2>"; # Primero hay que "preparar" el query $sth = $dbh->prepare($query); # Ejecutamos el query $sth->execute or print "Ha fallado la consulta query"; #indicamos que vamos a imprimir HTML print "<html><head><title>Consulta de Estado</title></head>\n"; print "<body>\n"; print "Variables -> $ENV{'QUERY_STRING'}\n"; # Recorremos los resultados obtenidos de la base de datos %almacen; while (($id, $fecha, $matricula) = $sth->fetchrow_array) { $almacen{$matricula}{'fecha_entrada'}=$fecha; $almacen{$matricula}{'estado'}=$estado; } print"</body></html>"; # Indicamos que hemos acabado y desconectamos $sth->finish(); $dbh->disconnect; exit 0;

In reply to Problem with mysql query using DBI::Mysql by Sombrerero_loco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.