<?php
/*****************************************************************************************************************************************
**************************************Class ConnectDatabase****CREATE DATE 29/10/2548 03.03.15 AM *************
**************************************Create by Revat Boonsit**** E-mail:[email protected]****************************
/*****************************************************************************************************************************************/
class ConnectDatabase { // start Class connectDatabase
var $host;
var $user;
var $password;
var $connnect;
var $select_db;
var $sql;
var $result;
var $result_num_row;
var $result_error;
var $result_array;
var $i;
function setHost($host_database,$user_name,$pass){ // start method setHost
$this->host=$host_database;
$this->user=$user_name;
$this->password=$pass;
} // end method setHost
function getHost($db_name,$sql_command){ // start method getHost
$this->connect=mysql_connect($this->host,$this->user,$this->password);
if(!$this->connect){ // check connection if have error must print error on browncer.
$this->result_error=mysql_error();
print "have error at".$this->result_error;
}else{
$this->select_db=mysql_select_db($db_name);
if(!$this->select_db){ // check select database if have error print error on browncer.
$this->result_error=mysql_error();
print "have error at".$this->result_error;
}else{ // if don't have error next step must query
$this->sql=$sql_command;
$this->result=mysql_query($this->sql);
$this->result_num_row=mysql_num_rows($this->result);
print "<table widht=\"150\" cellpadding=\"0\" cellspacing=\"2\" border=\"1\">";
for($this->i=0;$this->result_num_row>$this->i;$this->i++){
$this->result_array=mysql_fetch_array($this->result);
print "<tr><td>".$this->result_array["fullname"]."</td></tr>";
}
print "</table>";
mysql_close($this->connect);
}
}
} // end method getHost.
} // end Class connecDatabase.
?>
<?php
/*********************************************************************************************************
/******************************data base**************************************************************
CREATE TABLE tb_user(
id_user int unsigned not null auto_increment primary key,
fullname varchar(100) not null
);
/********************************************************************************************************/
$host_database="<insert name your host>";
$user_name="<insert your user_name for database>";
$pass="<insert password for database";
$db_name="<insert database name>";
$sql_command="<insert SQL command>";
$conn=new ConnectDatabase(); // post $conn for new object from class ConnectDatabase.
$conn->setHost($host_database,$user_name,$password); // post $conn for use method setHost and put argument.
$show=$conn->getHost($db_name,$sql_command); // post $show for use method getHost and put argument.
print $show; // print show on browncer.
?>
<?php
/*****************************************************************************************************************************************
**************************************Class ConnectDatabase****CREATE DATE 29/10/2548 03.03.15 AM *************
**************************************Create by Revat Boonsit**** E-mail:[email protected]****************************
/*****************************************************************************************************************************************/
class ConnectDatabase { // start Class connectDatabase
var $host;
var $user;
var $password;
var $connnect;
var $select_db;
var $sql;
var $result;
var $result_num_row;
var $result_error;
var $result_array;
var $i;
function setHost($host_database,$user_name,$pass){ // start method setHost
$this->host=$host_database;
$this->user=$user_name;
$this->password=$pass;
} // end method setHost
function getHost($db_name,$sql_command){ // start method getHost
$this->connect=mysql_connect($this->host,$this->user,$this->password);
if(!$this->connect){ // check connection if have error must print error on browncer.
$this->result_error=mysql_error();
print "have error at".$this->result_error;
}else{
$this->select_db=mysql_select_db($db_name);
if(!$this->select_db){ // check select database if have error print error on browncer.
$this->result_error=mysql_error();
print "have error at".$this->result_error;
}else{ // if don't have error next step must query
$this->sql=$sql_command;
$this->result=mysql_query($this->sql);
$this->result_num_row=mysql_num_rows($this->result);
print "<table widht=\"150\" cellpadding=\"0\" cellspacing=\"2\" border=\"1\">";
for($this->i=0;$this->result_num_row>$this->i;$this->i++){
$this->result_array=mysql_fetch_array($this->result);
print "<tr><td>".$this->result_array["fullname"]."</td></tr>";
}
print "</table>";
mysql_close($this->connect);
}
}
} // end method getHost.
} // end Class connecDatabase.
?>
<?php
/*********************************************************************************************************
/******************************data base**************************************************************
CREATE TABLE tb_user(
id_user int unsigned not null auto_increment primary key,
fullname varchar(100) not null
);
/********************************************************************************************************/
$host_database="<insert name your host>";
$user_name="<insert your user_name for database>";
$pass="<insert password for database";
$db_name="<insert database name>";
$sql_command="<insert SQL command>";
$conn=new ConnectDatabase(); // post $conn for new object from class ConnectDatabase.
$conn->setHost($host_database,$user_name,$password); // post $conn for use method setHost and put argument.
$show=$conn->getHost($db_name,$sql_command); // post $show for use method getHost and put argument.
print $show; // print show on browncer.
?>