Wednesday, February 6, 2008

PHP Table Class

Here is the link to my new class : PHP Table Class

Monday, February 4, 2008

Simple PHP Database Connection Class

server  = $_DBINFO['server'];
$this->username = $_DBINFO['username'];
$this->password = $_DBINFO['password'];
$this->database = $_DBINFO['database'];
$this->connect();
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxx CREATES A SERVER CONNECTION xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function connect(){
$this->conn = @mysql_connect($this->server, $this->username, $this->password);
if($this->conn == FALSE){
echo 'Cannot connect to server \''.$this->server.'\'.'; exit;
}
$dbconnect = @mysql_select_db($this->database, $this->conn);
if($dbconnect == FALSE){
echo 'Unable to connect to database \''.$this->database.'\''; exit;
}
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxx PROCESS SQL QUERY xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function query($sql){
$this->query = @mysql_query($sql, $this->conn) or print_r(mysql_error());
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxx QUERY RESULT IN ARRAY FORM xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function getRecord(){
$resultCount = mysql_num_rows($this->query);

if ($resultCount==1){
$result = @mysql_fetch_assoc($this->query);
}
else if ($resultCount > 1){
while($row = @mysql_fetch_assoc($this->query)){
$result[]=$row;
}
}
else{
$result = NULL;
}
return $result;
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxx GET TOTAL RESULT COUNT xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function query_count(){
return @mysql_num_rows($this->query);
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxx GET LAST INSERTED ID xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function last_insert_id(){
return @mysql_insert_id($this->conn);
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxx RETURN ONLY ONE SPECIFIC FIELD xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function getField($fieldname){
while($row = @mysql_fetch_assoc($this->query)){
$result[]=$row[$fieldname];
}
return $result;
}
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxx HOW-TO-USE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// A simple demo on how to use this module
// DIRECTION: download file and save then remove the ".txt" extension to be saved as a php file
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/*
// ASSIGN DATABASE SERVER INFO INTO ARRAY VALUES
$serverInfo['server'] = 'localhost';
$serverInfo['username'] = 'root';
$serverInfo['password'] = '';
$serverInfo['database'] = 'rednixchat';

// CREATE NEW Database OBJECT
$db = new Database($serverInfo)

// CREATE AN SQL STATEMENT
$sqlSelect = "SELECT * FROM user_info";

// PERFORM SQL STATEMENT ASSIGNED IN $sqlSelect
$db->query($sqlSelect);

// GET TOTAL RESULT FOR SQL QUERY
$totalResult = $db->query_count();

// GET QUERY RESULT IN ARRAY FORM
$queryResult = $db->getRecord();

// DISPLAY QUERY RESULT
print_r($queryResult);
*/
?>

Wednesday, December 12, 2007

Personal logo

I have created a personal logo for this blog.
You can view the post and the logo here
"Jhoy Imperial and the Web logo"