<?
class connectDB{
//public $Sql="";
var $query="";
var $host="";// host name
var $user="";// user name
var $pw="";// password database
var $dbname="";// database name
var $fetch_arr;
public function connect($new_host="",$new_user="",$new_pw="",$new_dbname=""){ //connectDB('host','user','pass',g'databaseName')
if($new_host!="")
$this->host=$new_host;
if($new_user!="")
$this->user=$new_user;
if($new_pw!="")
$this->pw=$new_pw;
if($new_dbname!="")
$this->dbname=$new_dbname;
mysql_connect($this->host,$this->user,$this->pw)or die("No connect Host");
mysql_select_db($this->dbname)or die('connect fail!!');
}//connect
public function qr($objQr){//Working mysql_query(); USE: $db->qr($sql);
$this->query=$objQr;
if($this->query!="")
return $this->query=mysql_query($this->query);
}
public function fetch_array($new_FetchArray){//$db->fetch_array($re); print $db->fetch_arr['FieldName'];
while($this->fetch_arr=mysql_fetch_array($new_FetchArray)){
return $this->fetch_arr;
}
}
}//class
?>
testpage.php
Code
<?php require('ClassConnectDB.inc.php');
$db= new connectDB();
$db->connect('localhost','user','pass','DBname');
$sql="SELECT * FROM table";
$re=$db->qr($sql);