connecting to a database (with no web server)

Discussion in 'Perl Misc' started by dominant, Aug 10, 2003.

  1. dominant

    dominant Guest

    Is this practicable?

    I observed that in the connect function we must specified the host. What
    if there is not web server?

    --
    Posted via http://dbforums.com
     
    dominant, Aug 10, 2003
    #1
    1. Advertising

  2. You should repeat the essence of your question in the message body:
    "connecting to a database (with no web server)"

    dominant wrote:
    > Is this practicable?


    Yes, of course it is.

    > I observed that in the connect function we must specified the host.
    > What if there is not web server?


    Which connect function are you talking about, and where did you
    observe that? Did you study the documentation for the module you are
    trying to use?

    The connect() method in DBI.pm does not require that host is specified.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 10, 2003
    #2
    1. Advertising

  3. dominant <> wrote:
    >
    > Is this practicable?



    Is what practicable?


    > I observed



    Where did you observe it?

    Show us what you saw, and we can help you interpret it.

    Keep it to yourself, and it is up to you to interpret it.


    > that in the connect function we must specified the host.



    I have never observed such a thing, so I am curious as to
    where you saw that.

    Where did you see that?


    > What
    > if there is not web server?



    Huh?

    You do not need a web server to run Perl programs whether they
    connnect to a database or not, so I dunno what you are getting
    at there...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Aug 10, 2003
    #3
  4. > Is this practicable?
    >
    > I observed that in the connect function we must specified the host.
    > What if there is not web server?


    host, in the DBI 'connect' method, refers to the host where the
    database resides. If you are using a modern RDBMS (ie MySQL,
    PostgreSQL, Sybase, Oracle, etc), this refers to where the database is
    'living'. So, for example, you are trying to connect to a MySQL
    database on the same machine as the script, the host is probably
    'localhost'.

    Please read the documentation more carefully. You may find what you
    need there.

    HTH

    Jim
     
    James Willmore, Aug 10, 2003
    #4
  5. dominant

    dominant Guest

    #!/usr/bin/perl
    #
    # Cannonical Perl DBI connection to Mysql.
    ##############################################################################


    use DBI;

    $db = "username"; # your username (= login name = account name )
    $host = "127.0.0.1"; # = "localhost", the server your are on.
    $user = $db; # your Database name is the same as your account name.
    $pwd = "mypassw"; # Your account password


    # connect to the database.


    $dbh = DBI->connect( "DBI:mysql:$db:$host", $user, $pwd)
    or die "Connecting : $DBI::errstr\n ";

    $sql = "SELECT * FROM blah_table";


    # executing the SQL statement.


    $sth = $dbh->prepare($sql) or die "preparing: ",$dbh->errstr;
    $sth->execute or die "executing: ", $dbh->errstr;

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


    # one of the functions to retrieve data from the table results
    # check perldoc DBI for more methods.


    while ($row = $sth->fetchrow_hashref)
    {
    print $row->{'some_field_name'},'<BR>';
    }

    That's it what i mean, the variable $host.

    If mysql runs under no web server what is going on then?

    Could post the ideal code for any database connection (and
    particularly Oracle)

    Thanks in advance!

    --
    Posted via http://dbforums.com
     
    dominant, Aug 10, 2003
    #5
  6. dominant wrote:
    >
    > use DBI;
    >
    > $host = "127.0.0.1"; # = "localhost", the server your are on.
    >
    > That's it what i mean, the variable $host.


    I see the variable $host, but what is the rest? A script that somebody
    wrote and that you are trying to install, or just some sample code
    related to the use of the DBI module? Whatever it is, did you ask the
    one who wrote it?

    Anyway, you could try to just keep '127.0.0.1' as the value of $host,
    or you could try to change it to 'localhost'.

    I couldn't help noticing that 'somebody' suggested that you "check
    perldoc DBI". Have you done so?

    http://search.cpan.org/author/TIMB/DBI-1.37/DBI.pm

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 10, 2003
    #6
  7. dominant wrote:
    > I just wanted to see how the DBI works for the Mysql.
    >
    > But now i want to conncet with the Oracle Server. The problem is
    > that is on another system(solaris) while the perl program which i
    > want to create is on a Windows system. In that case, what is the
    > $host variable i should define?


    Dear "dominant",

    This group is for discussing the Perl language:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

    Since your question(s) are not about Perl problems, this is not the
    right place.

    When reading that last question, I believe that there are quite a few
    pieces that you need to get in place, and that the value of that $host
    variable is your least problem...

    Guess you should buy a book, and start learning some basics about and
    the difference between things like
    - a (SQL) database
    - a server
    - an operating system

    Good luck!

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 10, 2003
    #7
  8. "dominant" <> wrote in message
    news:...
    >
    > The script comes from http://www.he.net/info/mysql/perldbi.html
    >
    > I just wanted to see how the DBI works for the Mysql.
    >
    > But now i want to conncet with the Oracle Server. The problem is that is
    > on another system(solaris) while the perl program which i want to create
    > is on a Windows system. In that case, what is the $host variable i
    > should define?
    >
    > --
    > Posted via http://dbforums.com


    If the host is called 'xyz.com', you set the host to 'xyz.com'.
    The host must be visible to you via your network as an IP address or domain
    name. You might need to open a port on the host to let your query through.

    gtoomey
     
    Gregory Toomey, Aug 10, 2003
    #8
  9. dominant

    Ron Reidy Guest

    $host is specific (I think) to mySQL. To be sure, look at the
    DBD::mysql docs. For Oracle, you need to:

    1. Read the DBI docs (perldoc DBI).
    2. Read the DBD::Oracle docs (perldoc DBD::Oracle)

    You may also want to familiarize yourself with Oracle networking (Net8)
    and remote access (assuming you are accessing an instance that is not on
    your windows machine).


    --
    Ron Reidy
    Oracle DBA

    dominant wrote:
    > The script comes from http://www.he.net/info/mysql/perldbi.html
    >
    > I just wanted to see how the DBI works for the Mysql.
    >
    > But now i want to conncet with the Oracle Server. The problem is that is
    > on another system(solaris) while the perl program which i want to create
    > is on a Windows system. In that case, what is the $host variable i
    > should define?
    >
    > --
    > Posted via http://dbforums.com
     
    Ron Reidy, Aug 11, 2003
    #9
  10. dominant

    dominant Guest

    To Ron Reidy

    Although, i have the DBI documents(perldoc DBI), however, when i tried
    to run "perldoc DBD::Oracle" i didn't recieve any results. That means i
    have the DBD for the Oracle, (nor Mysql).

    Should i download extra packages?

    --------------

    I understood that the $host variable must be specified as the private IP
    within the private network.

    --
    Posted via http://dbforums.com
     
    dominant, Aug 11, 2003
    #10
  11. dominant

    Ron Reidy Guest

    You can access them online:

    http://search.cpan.org/author/TIMB/DBD-Oracle-1.14/Oracle.pm
    http://search.cpan.org/author/RUDY/DBD-mysql-2.9002/lib/DBD/mysql.pm

    To install DBD::Oracle for AS Perlm you will need to install Perl v5.6.x
    (I recommend 5.6.1), since Perl 5.8.0 does not have a ppm for DBD::Oracle.


    --
    Ron Reidy
    Oracle DBA


    dominant wrote:
    > To Ron Reidy
    >
    > Although, i have the DBI documents(perldoc DBI), however, when i tried
    > to run "perldoc DBD::Oracle" i didn't recieve any results. That means i
    > have the DBD for the Oracle, (nor Mysql).
    >
    > Should i download extra packages?
    >
    > --------------
    >
    > I understood that the $host variable must be specified as the private IP
    > within the private network.
    >
    > --
    > Posted via http://dbforums.com



    --
    Ron Reidy
    Oracle DBA
     
    Ron Reidy, Aug 11, 2003
    #11
  12. dominant

    dominant Guest

    I downloaded the source, as it is mentioned, oracle.pm. What can i do
    with that?

    --
    Posted via http://dbforums.com
     
    dominant, Aug 11, 2003
    #12
  13. dominant

    J. Gleixner Guest

    dominant wrote:
    > I downloaded the source, as it is mentioned, oracle.pm. What can i do
    > with that?


    First, read the README file. It should answer how to test and install
    the module. Then install it.
     
    J. Gleixner, Aug 11, 2003
    #13
  14. <snip>
    > $host = "127.0.0.1"; # = "localhost", the server your are on.


    The '#' is a comment - and it's states what $host means (although, I
    would have wrote - "the server you wish to connect to").
    The numbers are the IP address for the host. To change the host you
    want to connect to, change the numbers to the proper IP address - or -
    use the hostname of the server you wish to connect to.

    <snip>
    >
    > Could post the ideal code for any database connection (and
    > particularly Oracle)


    Install the DBD::Oracle module. HOWEVER, BEFORE you install the
    module - READ the documentation FIRST. If you have questions specific
    to how to use the module, then feel free to post them here -
    otherwise, do not post non-Perl questions here.

    HTH

    Jim
     
    James Willmore, Aug 12, 2003
    #14
  15. dominant

    Ron Reidy Guest

    Read the README files. Follow the instructions exactly. If you are on
    Windows using AS Perl
    , install via ppm.
    dominant wrote:
    > I downloaded the source, as it is mentioned, oracle.pm. What can i do
    > with that?
    >
    > --
    > Posted via http://dbforums.com



    --
    Ron Reidy
    Oracle DBA
     
    Ron Reidy, Aug 12, 2003
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ann Marinas
    Replies:
    12
    Views:
    760
    Guest
    May 5, 2005
  2. Ben
    Replies:
    5
    Views:
    261
    Joe Kaplan \(MVP - ADSI\)
    Mar 31, 2006
  3. David Thielen
    Replies:
    3
    Views:
    1,632
    Steven Cheng [MSFT]
    Sep 1, 2008
  4. Replies:
    1
    Views:
    136
    ChrisH
    Jul 19, 2006
  5. Arthur Zubarev
    Replies:
    0
    Views:
    90
    Arthur Zubarev
    Feb 3, 2014
Loading...

Share This Page