This will be my first time to write a code to display records from MySQL using PERL as my programming language. I have to install DBD-mysql library in order for me to connect PERL script into MySQL database. The code is very short and easy to understand.
I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Installation of DBD-mysql library in the ActivePerl directory
Display of Records using PERL and MySQL
Program Listing
display.cgi
#!"C:\perl\bin\perl.exe"
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use DBI;
use CGI;
print "Content-type: text/html \n\n";
# MYSQL CONFIG VARIABLES
$host = "localhost";
$database = "payroll";
$tablename = "employees";
$user = "root";
$pw = "";
# PERL MYSQL CONNECT()
$driver = "DBI:mysql:database=$database;host=$host";
$connect = DBI->connect($driver, $user, $pw);
# SELECT DB
$run_query = $connect->prepare("SELECT * FROM $tablename");
$run_query->execute();
print "<h2> Display Record in Perl and MySQL </h2>";
print "<h3> Created By Mr. Jake R. Pomperada, MAED-IT </h3>";
print "<br>";
# HTML TABLE
print "<table border='1'><tr>
<th>ID</th>
<th>LAST NAME</th>
<th>FIRST NAME</th>
<th>POSITION</th>
</tr>";
# FETCHROW ARRAY
while (@results = $run_query->fetchrow_array()) {
print "<tr><td>"
.$results[0]."</td><td>"
.$results[1]."</td><td>"
.$results[2]."</td><td>"
.$results[3]."</td></tr>";
}
print "</table>";
employees.sql
-- phpMyAdmin SQL Dump
-- version 4.7.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Apr 27, 2018 at 05:21 PM
-- Server version: 10.1.28-MariaDB
-- PHP Version: 7.1.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `payroll`
--
-- --------------------------------------------------------
--
-- Table structure for table `employees`
--
CREATE TABLE `employees` (
`id` int(11) NOT NULL,
`lastname` varchar(200) NOT NULL,
`firstname` varchar(200) NOT NULL,
`position` varchar(200) NOT NULL,
`dayswork` int(10) NOT NULL,
`rate` decimal(10,2) NOT NULL,
`salary` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `employees`
--
INSERT INTO `employees` (`id`, `lastname`, `firstname`, `position`, `dayswork`, `rate`, `salary`) VALUES
(30, 'BRYANT', 'KOBE', 'SENIOR MANAGER', 30, '123.73', '3711.90'),
(32, 'JORDAN', 'MICHAEL', 'CLERK', 10, '250.16', '2501.60'),
(33, 'MORENO', 'ALMA', 'SALES CONSULTANT', 15, '341.53', '5122.95'),
(34, 'PASCUAL', 'PIOLO', 'ACTOR', 13, '234.79', '3052.27'),
(45, 'UY', 'MIKE', 'CARPENTER', 14, '100.59', '1408.26'),
(46, 'POMPERADA', 'JAKE', 'SOFTWARE ENGINEER TEAM LEAD', 0, '0.00', '0.00'),
(47, 'POMPERADA', 'MA. JUNALLIE', 'SYSTEM ARCHITECT', 0, '0.00', '0.00'),
(48, 'POMPERADA', 'JACOB SAMUEL', 'SOFTWARE DEVELOPER / TESTER', 1, '1.00', '1.00'),
(49, 'POMPERADA', 'JULIANNA RAE', 'SOFTWARE MANAGER / QUALITY ASSURANCE MANAGER', 0, '0.00', '0.00'),
(50, 'POMPERADA', 'LYDIA', 'FINANCE MANAGER', 1, '11.00', '1.00'),
(51, 'POMPERADA', 'VIRGILIO', 'SOFTWARE DESIGNER AND TRAINOR', 1, '1.00', '1.00');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `employees`
--
ALTER TABLE `employees`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `employees`
--
ALTER TABLE `employees`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=52;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
No comments:
Post a Comment