Help connection to mysql database

zilore mumba <[email protected]> Tue, 25 Jun 2013 15:04:16 -0700 (PDT)
Newsgroups gmane.comp.lang.perl.active-perl
Message-ID <[email protected]>
--===============1737082083==
Content-Type: multipart/alternative;
	boundary="1494295045-1997256725-1372197856=:84744"

--1494295045-1997256725-1372197856=:84744
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Excuse my total ignorance on the above subject. I am trying to access a mys=
ql database via a perl script, and I came across the example below, but am =
not sure whether my are correctly filled (where marked ####################=
#### below).=0AI would appreciate assistance to clarify what should actuall=
y go into those fileds.=0ASecondly when I run my script, it says $rv and $r=
c are used once.=0AWill appreciate=0AZilore=0A=0A=0Aprint "Content-type: te=
xt/html\n\n";=0A=0A## mysql user database name=0A$db =3D"IP address";=A0=A0=
=A0=A0=A0=A0=A0=A0 # should the IP address be here or I just put MySQL? ###=
#####################=0A## mysql database user name=0A$user =3D "myuser";=
=0A=A0=0A## mysql database password=0A$pass =3D "mypass";=0A=A0=0A## user h=
ostname : This should be "localhost" but it can be diffrent too=0A#$host=3D=
"localhost";=0A$host=3D"localhost";=A0 # is this ok or should I put the IP =
address here? ######################## =0A=0A## SQL query=0A$query =3D "sho=
w tables";=0A=A0=0A#$dbh =3D DBI->connect("DBI:mysql:$db:$host", $user, $pa=
ss);=0A$dbh =3D DBI->connect("DBI:mysql:$db:$host", $user, $pass);=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 # should it be DBI:mysql? or ? ########################=
=0A$sqlQuery=A0 =3D $dbh->prepare($query) or die "Can't prepare $query: $db=
h->errstr\n";=0A=A0=0A$rv =3D $sqlQuery->execute or die "can't execute the =
query: $sqlQuery->errstr";=0A=A0=0Aprint "<h3>********** My Perl DBI Test *=
**************</h3>";=0Aprint "<p>Here is a list of tables in the MySQL dat=
abase $db.</p>";=0Awhile (@row=3D $sqlQuery->fetchrow_array()) {=0Amy $tabl=
es =3D $row[0];=0Aprint "$tables\n<br>";=0A}=0A$rc =3D $sqlQuery->finish;=
=0Aexit(0);
--1494295045-1997256725-1372197856=:84744
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

<html><body><div style=3D"color:#000; background-color:#fff; font-family:ta=
homa, new york, times, serif;font-size:12pt"><div>Excuse my total ignorance=
 on the above subject. I am trying to access a mysql database via a perl sc=
ript, and I came across the example below, but am not sure whether my are c=
orrectly filled (where marked ######################## below).</div><div>I =
would appreciate assistance to clarify what should actually go into those f=
ileds.</div><div>Secondly when I run my script, it says $rv and $rc are use=
d once.</div><div>Will appreciate</div><div>Zilore</div><div><br></div><div=
 style=3D"color: rgb(0, 0, 0); font-size: 16px; font-family: tahoma,new yor=
k,times,serif; background-color: transparent; font-style: normal;"><br></di=
v><div style=3D"color: rgb(0, 0, 0); font-size: 16px; font-family: tahoma,n=
ew york,times,serif; background-color: transparent; font-style: normal;">pr=
int "Content-type: text/html\n\n";<br><br>## mysql user database
 name<br>$db =3D"IP address";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; # should the IP address be here or I just put MySQL? ###################=
#####<br>## mysql database user name<br>$user =3D "myuser";<br>&nbsp;<br>##=
 mysql database password<br>$pass =3D "mypass";<br>&nbsp;<br>## user hostna=
me : This should be "localhost" but it can be diffrent too<br>#$host=3D"loc=
alhost";<br>$host=3D"localhost";&nbsp; # is this ok or should I put the IP =
address here? ######################## <br><br>## SQL query<br>$query =3D "=
show tables";<br>&nbsp;<br>#$dbh =3D DBI-&gt;connect("DBI:mysql:$db:$host",=
 $user, $pass);<br>$dbh =3D DBI-&gt;connect("DBI:mysql:$db:$host", $user, $=
pass);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # should it be=
 DBI:mysql? or ? ########################<br>$sqlQuery&nbsp; =3D $dbh-&gt;p=
repare($query) or die "Can't prepare $query: $dbh-&gt;errstr\n";<br>&nbsp;<=
br>$rv =3D $sqlQuery-&gt;execute or die "can't execute the query:
 $sqlQuery-&gt;errstr";<br>&nbsp;<br>print "&lt;h3&gt;********** My Perl DB=
I Test ***************&lt;/h3&gt;";<br>print "&lt;p&gt;Here is a list of ta=
bles in the MySQL database $db.&lt;/p&gt;";<br>while (@row=3D $sqlQuery-&gt=
;fetchrow_array()) {<br>my $tables =3D $row[0];<br>print "$tables\n&lt;br&g=
t;";<br>}<br>$rc =3D $sqlQuery-&gt;finish;<br>exit(0);<br><br></div></div><=
/body></html>
--1494295045-1997256725-1372197856=:84744--

--===============1737082083==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1737082083==--