LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   starting on perl (https://www.linuxquestions.org/questions/programming-9/starting-on-perl-307023/)

ankscorek 03-28-2005 11:08 AM

starting on perl
 
helloo i have created a backend for a database in mySQl
i want to make a frontend using perl

how do i go abt it
i am an absolute starter at this so it will be appreciated if someone can guide me to an ebook regarding building a frontened using perl

masand 03-28-2005 11:15 AM

hi there

u can have a look at all the man pages of perl using

apropos perl

also have a look athe code of webmin that will help

regards

TheLinuxDuck 03-28-2005 02:44 PM

In order to connect with a mySQL DB in perl, you're going to need to install the DBI/DBD modules.. they may come with newer installs of perl, but I don't know for certain. The INSTALL and README files in the module archives will tell you exactly what components you need to install..

The DBI package:
http://cpan.uwinnipeg.ca/dist/DBI

The DBD-mysql driver package:
http://cpan.uwinnipeg.ca/dist/DBD-mysql

I feel like there's one more thing that needs to be installed, but it's escaping me at the moment.. the README/INSTALL's for the DBI and DBD-mysql will tell you everything that you'll need installed.

As for perl, making a connection is pretty easy:
Code:

use DBI;

my($sqlDBName) = 'geography';
my($sqlDBUser) = 'Steve';
my($sqlDBpass) = 'getstuffed';

my($db) = DBI->connect("DBI:mysql:$sqlDBName", $sqlDBUser, $sqlDBPass) or
  die "Error connecting to $sqlDBName: ", $DBI::errstr, "\n";

Then create your query string, prepare it, then execute it:
Code:

my($query) = "SELECT * from country";
my($call) = $db->prepare($query);
if(!defined($call)) {
  die "Prepare failed on query '$query'.\n",
      "Reason: ", $db->errstr, "\n";
}
else {
  if(!$call->execute()) {
  die "Execute failed on query '$query'.\n",
      "Reason: ", $db->errstr, "\n";
  }
}

Then, it's a matter of looping through the results, depending on whether you want to use an array or a hash.

You can take a look at here at the manpage of DBD-mysql for more examples and information about the connection.

Another question is, when you say beginner, does that mean in perl, with CGI's or what?

ankscorek 03-30-2005 09:48 PM

well thanx for all the help ...i am an absolute newbie at perl..like to start off from absolute basics


All times are GMT -5. The time now is 07:02 AM.