It’s been a while since II ‘d like to share more on ADODB for PHP. Download the API here - http://adodb.sourceforge.net/ and copy to your PHP project folder. In this case am using XAMPP standard installation.
ADOdb is a database abstraction library (API/framework) for PHP that support mostly major database server, among others MySQL, MSSQL, Oracle etc...
Let say you have this table contact(idstaf, nama, jawatan, email,mobile,ext, web, idjabatan,imej), from database mobile_fstm.
SQL-dump
-- phpMyAdmin SQL Dump
-- version 4.0.9
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Aug 09, 2015 at 05:56 AM
-- Server version: 5.6.14
-- PHP Version: 5.5.6
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
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 utf8 */;
--
-- Database: `mobile_fstm`
--
CREATE DATABASE IF NOT EXISTS `mobile_fstm` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `mobile_fstm`;
-- --------------------------------------------------------
--
-- Table structure for table `contact`
--
CREATE TABLE IF NOT EXISTS `contact` (
`idstaf` varchar(4) NOT NULL,
`nama` text NOT NULL,
`jawatan` text NOT NULL,
`email` text NOT NULL,
`mobile` text NOT NULL,
`ext` varchar(4) NOT NULL,
`web` text NOT NULL,
`idjabatan` varchar(5) NOT NULL,
`imej` text NOT NULL,
PRIMARY KEY (`idstaf`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `contact`
--
INSERT INTO `contact` (`idstaf`, `nama`, `jawatan`, `email`, `mobile`, `ext`, `web`, `idjabatan`, `imej`) VALUES
('0001', 'Muizz Salleh', 'Timbalan Dekan Mahasiswa', 'Muizz.Salleh@gmail.com', '+6012345234', '2313', 'http://muizz.com.my', 'JMM', 'muizz.png'),
('0132', 'Khirulnizam Abd Rahman', 'Pensyarah', 'khirulnizam@kuis.edu.my', '+60129034614', '2345', 'http://kerul.net', 'JSK', 'khirulnizam.jpg'),
('9999', 'Mohd Asyraf Chunawi', 'Trainee', 'masyrafchunawi@gmail.com', '+6012345678', '-', 'http://fstm.kuis.edu.my', 'JSK', 'asyraf.jpg');
/*!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 */;
Connecting and fetching records from table.
<?php
//Test AdoBD...
$server="localhost";
$user="root";
$pwd="";
$db="mobile_fstm";
//incude adodb5 library
include('adodb5/adodb.inc.php');
//select what database server is used
$DB = NewADOConnection('mysql');
//provide database server connection details
$DB->Connect($server, $user, $pwd, $db);
// M'soft style data retrieval with binds
$rs = $DB->Execute("select * from contact");
//resultset available
while (!$rs->EOF) {
//just browse thru all records
print_r($rs->fields);
$rs->MoveNext();
echo "<hr>";
}
?>
Output
Incorporating jquery-mobile in the interface.
Code
<!DOCTYPE html>
<html>
<head>
<title>Direktori FSTM </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header"
data-add-back-btn="true" data-back-btn-text="Kembali" data-position="fixed">
<h1>Hubungi FSTM.kuis.edu.my</h1>
</div><!-- /header -->
<div role="main" class="ui-content">
<!-- display list staff -->
<?php
//contact(idstaf, nama, jawatan, email,mobile,ext, web, idjabatan,imej), from database mobile_fstm.
//include ("conn.cfg.php");
//Test AdoBD...
$server="localhost";
$user="root";
$pwd="";
$db="mobile_fstm";
//incude adodb5 library
include('adodb5/adodb.inc.php');
//select what database server is used
$DB = NewADOConnection('mysql');
//provide database server connection details
$DB->Connect($server, $user, $pwd, $db);
// get resultset as associative array
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
// M'soft style data retrieval with binds
$rs = $DB->Execute("select * from contact");
//resultset available
?>
<ul data-role="listview" data-inset="true">
<?php
while (!$rs->EOF) {
//just browse thru all records
?>
<li>
<a href="#">
<?php echo $rs->fields['nama']; ?><br>
<?php echo $rs->fields['jawatan']; ?><br>
<?php echo $rs->fields['email']; ?><br>
<?php echo $rs->fields['mobile']; ?>
</a>
</li>
<?php
$rs->MoveNext();
//echo "<hr>";
}//end while EOF
?>
</ul>
<br>
</div>
<div data-role="footer" data-position="fixed">
<nav data-role="navbar">
<ul>
<li><a href="index.html" data-icon="home">Home</a></li>
<li><a href="info.html" data-icon="info">Info</a></li>
</ul>
</nav>
</div>
</div>
<!-- /page -->
</body>
</html>
ACTIVERECORD – all table and fields mapped to PHP class.
Training with sifoo blog.NasrulHazim.com
Comments
Post a Comment