/*
* Utility routines for MySQL.
*/
class MySQL_class {
var $db, $id, $result, $rows, $data, $a_rows, $dataRowsArray;
var $user, $pass, $host;
var $conn;
/* Make sure you change the USERNAME and PASSWORD to your name and
* password for the DB
*/
function Setup ($user, $pass) {
$this->user = $user;
$this->pass = $pass;
}
function Connect ($db) {
if (!$this->user) {
//$this->user = "itjobsli";
$this->user = "relcosys19_hid";
}
if (!$this->pass) {
$this->pass = "MmPPBWAe";
}
if (!$this->host) {
$this->host = "localhost";
}
$db = "relcosys19_hid";
$this->db = $db;
//*******************************************************************
$con = new mysqli($this->host, $this->user, $this->pass, $db);
if ($con->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
$this->conn=$con;
//////////$this->id = @mysql_pconnect($this->host, $this->user, $this->pass);
/*
$ri=1;
while ( ($this->id===false) && ($ri<50) ){
$ri++;
$this->id = @mysql_pconnect($this->host, $this->user, $this->pass);
}
if ($this->id===false){
MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host : '$SERVER_NAME'");
}
*/
//*******************************************************************
// $this->selectdb($db);
}
function SelectDB ($db) {
@mysql_select_db($db, $this->id) or
MySQL_ErrorMsg ("Unable to select database: $db");
}
# Use this function is the query will return multiple rows. Use the Fetch
# routine to loop through those rows.
function Query ($query) {
$dbcon=$this->conn;
$this->result = mysqli_query($this->conn, $query) or die(mysqli_error($dbcon));
$this->rows = mysqli_num_rows($this->result);
$this->a_rows = $this->conn->affected_rows;
$arrayofrows = array();
while($row = mysqli_fetch_array($this->result) )
{
array_push($arrayofrows,$row);
}
$this->dataRowsArray=$arrayofrows;
}
function Fetch ($row) {
$arrayofrows=$this->dataRowsArray;
$this->data=$arrayofrows[$row];
//print_r($this->data);
}
function Insert ($query) {
//echo $query;
mysqli_query($this->conn, $query) or die(mysqli_error());
echo mysqli_error($mysqli);
$this->a_rows = $this->conn->affected_rows;
}
function Update ($query) {
$this->result = mysqli_query($this->conn, $query) or die(mysqli_error());
$this->a_rows = $this->conn->affected_rows;
}
function Delete ($query) {
$this->result = mysqli_query($this->conn, $query) or die(mysqli_error());
$this->a_rows = $this->conn->affected_rows;
}
function quote_smart($value){
// Stripslashes is gpc on
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote if not a number or a numeric string
if ( !is_numeric($value) )
{
$value = mysqli_real_escape_string($this->conn,$value);
}
return $value;
}
}
/* ********************************************************************
* MySQL_ErrorMsg
*
* Print out an MySQL error message
*
*/
function MySQL_ErrorMsg ($msg) {
# Close out a bunch of HTML constructs which might prevent
# the HTML page from displaying the error text.
echo("\n");
echo("\n");
# Display the error message
$text = " Error: $msg :";
$text .= mysql_error();
$text .= "