renzo rizzato wrote:
Hallo to all,

Hello,

I am trying to access my MySQL database using the following PERL script:

use strict; use warnings;

use DBI;
use CGI qw(:standard);

print "Content-type: text/html\n\n";

print "<HTML>\n<HEAD>\n<BODY>\n</HEAD>";

1       $host = "xxx.xxx.xxx.xxx";
2       $database = "my_db_name";
3       $user = "my_user_name";
4       $password = "my_db_passwd";

5 $dbh = DBI -> connect ("DBI:mysql:host= $host; database = $database", $user,password);


or die DBI->errstr();

6 $sth = $dbh -> prepare ("select name, wins, losses from teams");

or die DBI->errstr();

7 $sth -> execute();

or die DBI->errstr();

8              while (@val = $sth -> fetchrow_array ()) {
9                     print p (sprintf ("name = $s, wins = $d, losses = $d\n",        
$val[0], $val[1], $val[2]));

What the heck is that doing? :)

passing sprintf()'s output to p() which is being passed to print() ? what is p() doing?

You may want to simplify it a bit:

print "name = $val[0], wins = $val[1], losses = $val[2]\n"; # I'm assuming since its text/html you'll want a <br /> tag in there also :)

10                    ++$count; }

11      $sth -> finish();
12      $dbh -> disconnect;

print "</P></FONT></BODY>\n</HTML>";


all I get from this is a white web page , the word "done" at page-foot. I suspect that connection has never occoured, also because I tryed to modify the parameters making them totally wrong, aspecting an error message telling me a "kick-off bloody foreigner!"

1) add use strict; use warnings; right above use DBI

2) my $dbh = DBI->connect(...) or die DBI->errstr();

That will actually print the error to the screen instead of giving you a blank stare.

That should get you started I hope :)

Lee.M - JupiterHost.Net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to