Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] need help with sort::fields

Expand Messages
  • Cristi Ocolisan
    Hello everyone! I have a problem I cannot solve alone. Please help me. I just started to work with MySQL and I m stuck. I wrote the following code to
    Message 1 of 3 , Mar 4, 2004
    • 0 Attachment
      Hello everyone!



      I have a problem I cannot solve alone. Please help me.



      I just started to work with MySQL and I'm stuck. I wrote the following code
      to interrogate a database called "ncp", but when I execute it only the first
      row from my table "persoane" is printed on screen.



      Can anyone tell me where I go wrong?



      Here is the code. For someone with experience it may look like very simple
      but again I just started to work with MySQL.





      #!/usr/bin/perl



      use DBI;

      use CGI;



      my $dsn = 'dbi:mysql:ncp';

      my $user = 'root';

      my $pass = '';



      #$nume = "Ocolisan";



      my $dbh = DBI->connect($dsn,$user,$pass) or die "Cannot connect!";



      my $sth = $dbh->prepare("select * from persoane");



      $sth->execute();



      while (@row = $sth->fetchrow_array()){

      print "$row[0] $row[1] $row[2] $row[3] $row[4] $row[5]<br>";

      }



      Thank you



      CO







      [Non-text portions of this message have been removed]
    • daymobrew@yahoo.com
      ... following code ... the first ... simple ... Looking at http://hantach.hypermart.net/perldoc/dbd-dbimodule.html I think you may need to change your DSN to
      Message 2 of 3 , Mar 4, 2004
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, "Cristi Ocolisan" <cristi@w...>
        wrote:
        > Hello everyone!
        >
        > I have a problem I cannot solve alone. Please help me.
        >
        > I just started to work with MySQL and I'm stuck. I wrote the
        following code
        > to interrogate a database called "ncp", but when I execute it only
        the first
        > row from my table "persoane" is printed on screen.
        >
        >
        >
        > Can anyone tell me where I go wrong?
        >
        >
        >
        > Here is the code. For someone with experience it may look like very
        simple
        > but again I just started to work with MySQL.
        >
        >
        > #!/usr/bin/perl
        >
        > use DBI;
        > use CGI;
        >
        > my $dsn = 'dbi:mysql:ncp';
        > my $user = 'root';
        > my $pass = '';
        >
        > #$nume = "Ocolisan";
        >
        > my $dbh = DBI->connect($dsn,$user,$pass) or die "Cannot connect!";
        >
        > my $sth = $dbh->prepare("select * from persoane");
        > $sth->execute();
        >
        > while (@row = $sth->fetchrow_array()){
        > print "$row[0] $row[1] $row[2] $row[3] $row[4] $row[5]<br>";
        > }
        >
        > Thank you
        >
        > CO

        Looking at
        http://hantach.hypermart.net/perldoc/dbd-dbimodule.html
        I think you may need to change your DSN to

        my $dsn = 'DBI:mysql:ncp'; # Caps for 'DBI'.

        Aside:
        1) Give the MySQL root user a password. It is very dangerous not to.
        2) Consider setting up a MySQL account which can only read the
        database. Then use this user in your script. This will ensure your CGI
        script cannot be used to change your database.
      Your message has been successfully submitted and would be delivered to recipients shortly.