connecting to a database (with no web server)

D

dominant

Is this practicable?

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

Gunnar Hjalmarsson

You should repeat the essence of your question in the message body:
"connecting to a database (with no web server)"
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.
 
T

Tad McClellan

dominant said:
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...
 
J

James Willmore

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
 
D

dominant

#!/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!
 
G

Gunnar Hjalmarsson

dominant said:
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
 
G

Gunnar Hjalmarsson

dominant said:
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!
 
G

Gregory Toomey

dominant said:
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?

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
 
R

Ron Reidy

$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).
 
D

dominant

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?
 
J

J. Gleixner

dominant said:
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

James Willmore

$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.

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
 
R

Ron Reidy

Read the README files. Follow the instructions exactly. If you are on
Windows using AS Perl
, install via ppm.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top