Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to connect to mySQL using Perl?

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
I posted this in both the mySQL forum and the Perl forum, but have not found a response yet- so I was hoping maybe some of you could help me on the basics of connecting to a mySQL database using Perl/CGI. Thanks... <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence."
 
first, you will need to install mysql, DBI, and DBD::mysql on your system.<br><br>if you have all that installed, then try my code below:<br><br>&nbsp;&nbsp;&nbsp;## connect to mysql<br>&nbsp;&nbsp;&nbsp;$dbh = DBI-&gt;connect('dbi:mysql:dbname','dbusername',dbpassword') ¦¦ die &quot;Cannot connect to mysql\n&quot;;<br><br>where you replace dbname,dbusername and dbpassword with your own value. to disconnect, use this:<br><br>&nbsp;&nbsp;&nbsp;## disconnect from mysql<br>&nbsp;&nbsp;&nbsp;$dbh-&gt;disconnect if($dbh);<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br>ttest<br>
:) happy programming :)
 
thanks. Is there a way to tell if I already have DBI and DBD::mysql installed? (I'm not the SysAdmin.) If not, how do I go about installing them? <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
use the following perl statement to test for DBI and DBD::mysql.<br><br>eval &quot;use DBI&quot;;<br>if ($@) { print &quot;DBI not installed.\n&quot;; }<br>else { print &quot;DBI present.\n&quot;; }<br><br>eval &quot;use DBD::mysql&quot;;<br>if ($@) { print &quot;DBD::mysql not installed.\n&quot;; }<br>else { print &quot;DBD::mysql present.&quot;; }<br><br>you can get more info at <A HREF=" TARGET="_new"> <p> <br><a href=mailto: > </a><br><a href= > </a><br>ttest<br>
:) happy programming :)
 
Thanks for the info, I'll try that. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top