Simple DB2 Query in Functions
This is a library for you to connect to DB2 with simpler query in array results.
Click Here to Download >>
================================================================
Module : PHP database class
Programmer : Mohd Izzairi Yamin
Date : 5/10/2007 9:30AM
Modified : 8/10/2007 12:12PM
================================================================
<?
session_name(”DBSESSID”);
session_start();
class connection {
function db_conn(){
global $conn;
$database = ‘UATBIND2′;
$user = ‘db2admin’;
$password = ‘db2admin’;
$hostname = ‘192.168.0.201′;
$port = 50000;
//To initialize the database connection
//with connection name,port,username & password
$conn = “DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;” .
“HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;”;
$conn = db2_connect($conn, ”, ”);
if ($conn) {
echo “”;
//db2_close($conn);
}
else {
echo “<center><b><br><br><br><font face=’tahoma’ color=’red’ size=’3′>Hahaha ! …. Database Server Down !</font><br>”;
echo “<font face=’tahoma’ color=’blue’ size=’3′>Please contact Mohd Izzairi Yamin </font><br></center>”;
error_reporting(0);
die();
}
return $conn;
}
// This function is for db2 to query the SQL statement
// where $sql is the parameters and will be read by the function
function db_query($sql) {
global $res_rs,$res,$conn,$b;
$res = “$sql”;
$res_rs=db2_prepare($conn,$res);
$b=db2_execute($res_rs);
return $res_rs;
return $b;
}
// This function is for db2 to get array results in row set from the SQL queried
function db_fetch_row($res_rs) {
global $arr;
$arr = db2_fetch_row($res_rs);
return $arr;
}
function db_array($val) {
global $res_rs,$arr;
$arr = db2_result($res_rs,$val);
return $arr;
}
// This function is for db2 to get array results from the SQL queried
function db_fetch_array($res_rs) {
global $arr;
$arr = db2_fetch_array($res_rs);
return $arr;
}
function check_session(){
if (!isset($_SESSION['USERNAME'])){
$goto=’../index.php’;
echo “<SCRIPT language=’JavaScript’>”;
echo “parent.window.location=’$goto’;”;
echo “</SCRIPT>”;
}
}
} // End Class Connection
?>
See more on how to implement
<?
/*================================================================
# Module : Creating simple database query with smarty templating
# Programmer : Mohd Izzairi Yamin
# Date : 8/10/2007 12:12PM
# Modified : 8/10/2007 12:12PM
================================================================*/
include_once”db2.php”;
include_once”lib/smarty.php”;
$db=new connection();
$db->db_conn();
$tpl=new dfs_sm();
$tpl->inc_tmp();
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
// Declare title for templating
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
$title=”Welcome to Xyiry Systems | Smart Business Solutions”;
$pathname=”index.tpl”;
$sql = “select * from x_user_records where username=’$username’”;
$stmt = $db->db_query($sql);
while($sql_rs2=$db->db_fetch_array($stmt)){
$tpl->name(’agent’,$sql_rs2[0]);
}
$tpl->name(’html_title’,$title);
$tpl->page($pathname);
?>
About this entry
You’re currently reading “Simple DB2 Query in Functions,” an entry on Xyiry PHP Blog | Where Open Source Lives
- Published:
- 08.13.07 / 3am
- Category:
- IBM DB2
No comments
Jump to comment form | comments rss [?] | trackback uri [?]