| Server IP : 10.200.247.200 / Your IP : 216.73.217.19 Web Server : Apache System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : jeremy ( 1001) PHP Version : 8.4.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/church_sites/lvsaints.com_meadowvalley/includes/ |
Upload File : |
<?php
/**
* /lib/mysql.php
*
* This file contains the MySQL class for connecting and querying the database
*
* @copyright 2016-2021 Synergy Pro Marketing
* @author Aaron Campbell <aaron@synergymentoring.com>
* @license None, All Rights Reserved
* @package Layout
* @filesource
*/
//Heavily modified by Jeremy Johnson to get it working with mysqli because mysql is no longer supported by php 7+
/**
* MySQL is a database connection class for connecting and querying a MySQL database
*
* Example usage:
* $db->query("SELECT * FROM table WHERE field = 1");
*
* @package MySQL
* @author Aaron Campbell <aaron@synergymentoring.com>
* @version $Revision: 1.3 $
* @access public
*/
$db = new MySQL('db.syndbs.com', 'lc2user', 'SYN57CRUZ', 'church_livestream');
class MySQL {
var $lastRecords;
var $lastQuery;
var $lastError;
var $lastID;
var $insert_id;
var $dbh;
/**
* returns the database connection as a standard PHP object
*
* @param string $host The database host address
* @param string $user The database username
* @param string $pass The database password
* @param string $db The name of the database to connect to
*/
function __construct(
$host = null,
$user = null,
$pass = null,
$db = null
) {
$this->connected = false;
if(!empty($db)) {
$this->conn_handle = mysqli_connect($host, $user, $pass, $db);
} else {
$this->conn_handle = mysqli_connect($host, $user, $pass);
}
if ($this->conn_handle) {
$this->connected = true;
$this->dbh = $this->conn_handle;
}
}
/** returns true if databse connects and false if does not */
function is_connected () {
return $this->connected;
}
/**
* returns a queries results as an array
*
* @param string $query_str A standard MySQL query string
*
* @return array On select queries will return an array of records, otherwise will return an empty array
*/
function query ($query_str, $is_assoc=true) {
$this->lastQuery = $query_str;
$records = Array();
if ($this->connected == true) {
$result = mysqli_query($this->conn_handle, $query_str);
$mysqlError = mysqli_error($this->conn_handle);
$this->lastError = $mysqlError;
if ( ! is_bool($result)) {
if($is_assoc) {
while ($rec = mysqli_fetch_assoc($result)) {
$records[] = $rec;
}
} else {
while ($rec = mysqli_fetch_array($result)) {
$records[] = $rec;
}
}
} else {
return $result;
}
$this->lastRecords = $records;
}
$this->last_insert_id();
return $records;
}
function get_results($query) {
$arr = $this->query($query);
$return = array();
if(!empty($arr)) {
foreach($arr as $k=>$v) {
$return[] = (object) $v;
}
}
return $return;
}
function clean($value) {
return mysqli_real_escape_string($this->conn_handle,$value);
}
function affected_rows() {
return mysqli_affected_rows($this->conn_handle);
}
function escape($value) {
return mysqli_real_escape_string($this->conn_handle,$value);
}
/**
* returns true when a query is run with no errors
*
* @return boolean Will return true when query is valid and false if the query is not valid
*/
function valid () {
return ($this->connected && mysqli_errno($this->conn_handle) == 0);
}
/**
* @return integer The error code for MySQL
*
* For codes and descriptions see: https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
* @see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
*/
function errno () {
if ($this->connected) {
return mysqli_errno($this->conn_handle);
} else {
return null;
}
}
/**
* @return string The error description
*/
function error () {
if ($this->connected) {
$mysqlError = mysqli_error($this->conn_handle);
$this->lastError = $mysqlError;
return $mysqlError;
} else {
return "";
}
}
/**
* @return mixed[] Will return the last inserted record's primary key value
*/
function last_insert_id () {
$id = mysqli_insert_id($this->conn_handle);
$this->lastID = $id;
$this->insert_id = $id;
if ($id == 0) {
return null;
} else {
return $id;
}
}
/**
* @return mixed[] Will return the last inserted record's primary key value
*/
function lastInsertId () {
$id = mysqli_insert_id($this->conn_handle);
$this->lastID = $id;
if ($id == 0) {
return null;
} else {
return $id;
}
}
function prettyJSON($json)
{
$result = '';
$level = 0;
$in_quotes = false;
$in_escape = false;
$ends_line_level = NULL;
$json_length = strlen( $json );
for( $i = 0; $i < $json_length; $i++ ) {
$char = $json[$i];
$new_line_level = NULL;
$post = "";
if( $ends_line_level !== NULL ) {
$new_line_level = $ends_line_level;
$ends_line_level = NULL;
}
if ( $in_escape ) {
$in_escape = false;
} else if( $char === '"' ) {
$in_quotes = !$in_quotes;
} else if( ! $in_quotes ) {
switch( $char ) {
case '}': case ']':
$level--;
$ends_line_level = NULL;
$new_line_level = $level;
break;
case '{': case '[':
$level++;
case ',':
$ends_line_level = $level;
break;
case ':':
$post = " ";
break;
case " ": case "\t": case "\n": case "\r":
$char = "";
$ends_line_level = $new_line_level;
$new_line_level = NULL;
break;
}
} else if ( $char === '\\' ) {
$in_escape = true;
}
if( $new_line_level !== NULL ) {
$result .= "\n".str_repeat( "\t", $new_line_level );
}
$result .= $char.$post;
}
return $result;
}
function debug ($return_string='0') {
$result = '<pre class="left">';
$result .= $this->lastQuery;
$result .= '<hr>';
$result .= $this->prettyJSON(json_encode($this->lastRecords));
$result .= '<hr>';
$result .= $this->lastError;
$result .= '<hr>';
$result .= $this->lastID;
$result .= '</pre>';
if(empty($return_string)) {
echo $result;
} else {
return $result;
}
}
/**
* @var object The connection handle
* @access private
*/
public $conn_handle;
/**
* @var boolean The connection status
* @access private
*/
public $connected;
}
;
/**
* returns a mysqli_real_escape_string cleaned string
*
* @param mixed[] $value The value to be cleaned
*
* @return string Will return a cleaned string that is safe to insert into the database
*/
if(!function_exists('clean')) {
function clean ($value) {
global $db;
return mysqli_real_escape_string($db->conn_handle,$value);
}
}
if(!function_exists('mysql_real_escape_string')) {
function mysql_real_escape_string ($value) {
global $db;
return mysqli_real_escape_string($db->conn_handle,$value);
}
}
if(!function_exists('mysql_insert_id')) {
function mysql_insert_id ($value) {
global $db;
return $db->last_insert_id();
}
}