/*
* Utility routines for MySQL.
*/
class MySQL_class {
var $db, $id, $result, $rows, $data, $a_rows, $dataRowsArray;
var $user, $pass, $host;
var $conn;
function Setup ($user, $pass) {
$this->user = $user;
$this->pass = $pass;
}
function Connect ($db) {
if (!$this->user) {
//$this->user = "itjobsli";
$this->user = "indur1kq_cqc";
}
if (!$this->pass) {
$this->pass = "carquotescentral";
}
if (!$this->host) {
$this->host = "localhost";
}
$db = "indur1kq_hid";
$this->db = $db;
//*******************************************************************
$con = new mysqli($this->host, $this->user, $this->pass, $db);
//$con = mysqli_connect($this->host, $this->user, $this->pass, $db);
if ($con->connect_errno) {
// echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}else{
// echo "DB Connect Successful";
}
$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 Query2($query) {
$dbcon=$this->conn;
//$dbcon = mysqli_connect("localhost","indur1kq_cqc","carquotescentral","indur1kq_hid");
if ($result = mysqli_query($dbcon, $query)) {
}
$this->result=$result;
$this->rows = ($this->result);
echo ("count is" . $this->rows);
$this->a_rows = $this->conn->affected_rows;
$arrayofrows = array();
while($row = mysqli_fetch_array($this->result) )
{
array_push($arrayofrows,$row);
}
$this->dataRowsArray=$arrayofrows;
}
function Query ($query) {
//$mysqli=new mysqli("localhost","indur1kq_cqc","carquotescentral","indur1kq_hid");
//if ($mysqli -> connect_errno) {
// echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
//exit();
// }
$mysqli=$this->conn;
if ($result = $mysqli -> query($query)) {
//echo "Returned rows are: " . $result -> num_rows;
// Free result set
$this->rows = $result -> num_rows;
//echo $this->rows;
$arrayofrows = array();
while ($row = $result -> fetch_assoc()) {
//printf ("%s (%s)\n", $row[0], $row[1]);
array_push($arrayofrows,$row);
}
$this->dataRowsArray=$arrayofrows;
$result -> free_result();
}else{
//echo "fetch error";
}
//$mysqli -> close();
}
function Fetch ($row) {
$arrayofrows=$this->dataRowsArray;
$this->data=$arrayofrows[$row];
//print_r($this->data);
}
function InsertOld ($query) {
mysqli_query($this->conn, $query) or die(mysqli_error());
echo mysqli_error($mysqli);
$this->a_rows = $this->conn->affected_rows;
}
function Insert($query) {
$sql = $query;
if ($this->conn->query($sql) === TRUE) {
//echo "New record created successfully";
} else {
//echo "Error: " . $sql . " Error: $msg :";
$text .= mysql_error();
$text .= "
" . $conn->error;
}
}
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 = "