I'm currently in the process of changing servers and this is the first time I've come across Mysql being set-up off the same server. The company I'm with used Perl to talk back and forth and frankly I have no perl experience. They are suggesting using the following code but when I place it inside my <?php ?> tags it give me a parse error. Can some help me by explaining how this works???
#!/usr/bin/perl
use DBI;
$dsn = "DBI:mysql:database=databasename";
$dbh=DBI->connect($dsn, "username", "password");
$sth = $dbh->prepare("SELECT * FROM table where ID=''5'' ORDER BY date");
$sth->execute;
while( (@results = $sth->fetchrow) != NULL) {
if ($results[2] > 500) {
print "$results[0] - $results[1] - $results[2] - $results[4] - $results[6]\n";
}
}
Thank you in advance...
Database access with the Perl DBI::DBD modules
Moderator: General Moderators
-
fandomfilms
- Forum Newbie
- Posts: 2
- Joined: Mon Jun 10, 2002 2:09 pm
- Location: Chicago
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
It won't work in PHP tags because it's perl and therefore a different language. If PHP is setup on the server there's no reason why you can't use PHP to make a connection to MySQL:
That's the code roughly translated.
Hope it helps,
Mac
Code: Select all
<?php
$user = ''; //your username for the database
$pass = ''; // your password for the database
$db = ''; // the name of your database
@$db_conn = mysql_connect('localhost', $user, $pass) or die(mysql_error());
@mysql_select_db($db) or die(mysql_error());
$sql = "SELECT * FROM table WHERE ID=5 ORDER BY date";
@$result = mysql_query($sql) or die(mysql_error());
while ($info = mysql_fetch_row($result)) {
if ($resultsї2] > 500) {
$output = implode(' - ', $info);
echo $output;
}
}
?>Hope it helps,
Mac