class Db_Mysqli {
static $hostname;
static $username;
static $password;
static $port;
static $database;
static $connection;
/**
*
* @param String $hostname
* @param String $username
* @param String $password
* @param String $database
* @param int $port
*/
public function __construct($hostname, $username, $password, $database = “”, $port = 3306) {
$this->hostname = $hostname;
$this->username = $username;
$this->password = $password;
$this->port = $port;
$this->database = $database;
$this->connection = mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port);
}
/**
* Close the mysql Connection with the Database Server.
*/
public function closeConnection() {
mysqli_close($this->connection);
}
/**
*
*
* @param String $query
* @return mysql result
*/
public function query($query) {
if ($query != “”) {
return mysqli_query($this->connection, $query);
} else {
return NULL;
}
}
/**
* return the mysqli_info result
*/
public function info() {
return mysqli_info($this->connection);
}
}
/* Example for using Db_Mysqli Class**/
class Example {
function example() {
$mysql = new Db_Mysqli (‘localhost’, ‘username’, ‘password’, ‘database’, 3306);
echo $mysql_info = $mysql->info();
$mysql_select_result = $mysql->query(“SELECT * FROM `Table`;”);
while ($row = mysqli_fetch_array($mysql_select_result)) {
echo $row;
}
$mysql->closeConnection();
}
}
- Jquery webcam plugin - June 19, 2016
- How To Add and Delete Users on a CentOSServer - June 5, 2016
- How To Set Up vsftpd on CentOS 6 - June 5, 2016