PHP Help – Write PHP into functions
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
// PHP Help – Write PHP into functions
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
*****************************************************************
Title : Writing PHP functions
Usage : to use only one type of sql_query with different databases
Purpose : mini database abstraction eg: sqlite and mysql
Programmer : Mohd Izzairi Yamin
Filename : library.php
******************************************************************
<?php
$database=”mysql”; // determine the database you want to use eg: mysql, sqlite
if ($database==”mysql”){
$db = mysql_pconnect(”localhost”,”root”,”root”);
mysql_select_db(”mobile”);
}
if ($database==”sqlite”){
$db = sqlite_open(’authentication.db’);
}
if ($database==”mysql”){
function db_query($sql){ // to remember the variable positioning
$res = mysql_query($sql);
return $res;
}
function db_fetch_array($res) {
$arr = mysql_fetch_assoc($res);
return $arr;
}
}
if ($database==”sqlite”){
global $db; // to get the value from outside the function
function db_query($sql) { // to remember the variable positioning
$res = sqlite_query($db,$sql);
return $res;
}
function db_fetch_array($res) {
$arr = sqlite_fetch_array($res);
return $arr;
}
}
//example of your SQL that you will be using in your codes are:
$res=db_query(”select * from table where field=’001′”);
$arr=db_fetch_array($res);
?>
About this entry
You’re currently reading “PHP Help – Write PHP into functions,” an entry on Xyiry PHP Blog | Where Open Source Lives
- Published:
- 08.10.07 / 4pm
- Category:
- PHP
No comments
Jump to comment form | comments rss [?] | trackback uri [?]