Last active
October 13, 2015 17:08
-
-
Save ChrisMoney/4228766 to your computer and use it in GitHub Desktop.
Perl - Select database and return data from it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Mysql; | |
print "Content-type: text/html \n\n"; | |
# MYSQL CONFIG VARIABLES | |
$host = "localhost"; | |
$database = "store"; | |
$tablename = "inventory"; | |
$user = "username"; | |
$pw = "password"; | |
# PERL MYSQL CONNECT() | |
$connect = Mysql->connect($host, $database, $user, $pw); | |
# SELECT DB | |
$connect->selectdb($database); | |
# DEFINE A MySQL QUERY | |
$myquery = "SELECT * FROM $tablename"; | |
# EXECUTE THE QUERY FUNCTION | |
$execute = $connect->query($myquery); | |
# HTML TABLE | |
print "<table border='1'><tr> | |
<th>id</th> | |
<th>product</th> | |
<th>quantity</th></tr>"; | |
# FETCHROW ARRAY | |
while (@results = $execute->fetchrow()) { | |
print "<tr><td>" | |
.$results[0]."</td><td>" | |
.$results[1]."</td><td>" | |
.$results[2]."</td></tr>"; | |
} | |
print "</table>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment