in my OC v.1.5.6.4+, I only have ONE Admin 'OpenShop' Extension 'Source File Editor', and if trying to execute it, it's producing a full page Server Error, with some 'illegal type compression message' coming from PHP 5.7, so, I had to re-define a lower PHP Version on the Server, to make it work again, for the time beeing, at least, because I really like this fine Code Editor, and would like to keep 'em.
--
It would be rather interesting, to find out, how older OC 'Programs' can be upmodded, in a way, possibly,
someone around here know's more about this.
---
Here are 4 different Files, to test, the TOP ONE is called:
mysqli.php
define('DB_DRIVER', 'mysqli');
Code: Select all
<?php
final class DBMySQLi {
private $link;
public function __construct($hostname, $username, $password, $database) {
$this->link = new mysqli($hostname, $username, $password, $database);
if (mysqli_connect_error()) {
throw new ErrorException('Error: Could not make a database link (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
$this->link->set_charset("utf8");
$this->link->query("SET SQL_MODE = ''");
}
public function query($sql) {
$query = $this->link->query($sql);
if (!$this->link->errno){
if (isset($query->num_rows)) {
$data = array();
while ($row = $query->fetch_assoc()) {
$data[] = $row;
}
$result = new stdClass();
$result->num_rows = $query->num_rows;
$result->row = isset($data[0]) ? $data[0] : array();
$result->rows = $data;
unset($data);
$query->close();
return $result;
} else{
return true;
}
} else {
throw new ErrorException('Error: ' . $this->link->error . '<br />Error No: ' . $this->link->errno . '<br />' . $sql);
exit();
}
}
public function escape($value) {
return $this->link->real_escape_string($value);
}
public function countAffected() {
return $this->link->affected_rows;
}
public function getLastId() {
return $this->link->insert_id;
}
public function __destruct() {
$this->link->close();
}
}
?>
-----------------------------
the second one is seemengly still called
mysql, but it contains
mysqli - routines:
mysql.php
define('DB_DRIVER', 'mysql');
-----------------------------
Code: Select all
<?php
final class MySQL {
private $link;
public function __construct($hostname, $username, $password, $database) {
$this->link = @new mysqli($hostname, $username, $password, $database);
if (mysqli_connect_error()) {
trigger_error('Error: Could not connect to database "' . $database . '"', E_USER_WARNING);
die;
}
$this->link->set_charset('utf8');
$this->link->query("SET SQL_MODE = ''");
}
public function query($sql) {
$resource = $this->link->query($sql);
if ($this->link->errno) {
trigger_error('Error: ' . $this->link->error . '<br />Error No: ' . $this->link->errno . '<br />' . $sql);
die;
}
if ($resource instanceof mysqli_result) {
$i = 0;
$data = array();
while ($result = $resource->fetch_assoc()) {
$data[$i] = $result;
$i++;
}
$resource->free();
$query = new stdClass();
$query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data;
$query->num_rows = $i;
unset($data);
return $query;
}
return $resource;
}
public function escape($value) {
return $this->link->real_escape_string($value);
}
public function countAffected() {
return $this->link->affected_rows;
}
public function getLastId() {
return $this->link->insert_id;
}
public function __destruct() {
if (!mysqli_connect_error()) {
$this->link->close();
}
}
}
?>
--------------------------------
or then, change your BOTH config.php files to: mysqliz, and use this one below:
define('DB_DRIVER', 'mysqliz');
--------------------------------
Code: Select all
<?php
final class MySQLiz {
private $mysqli_handler;
public function __construct($hostname, $username, $password, $database) {
$this->mysqli_handler = new mysqli($hostname, $username, $password, $database);
if ($this->mysqli_handler->connect_error) {
trigger_error('Error: Could not make a database link (' . $this->mysqli_handler->connect_errno . ') ' . $this->mysqli_handler->connect_error);
}
$this->mysqli_handler->query("SET NAMES 'utf8'");
$this->mysqli_handler->query("SET CHARACTER SET utf8");
$this->mysqli_handler->query("SET CHARACTER_SET_CONNECTION=utf8");
$this->mysqli_handler->query("SET SQL_MODE = ''");
}
public function query($sql) {
$result = $this->mysqli_handler->query($sql, MYSQLI_STORE_RESULT);
if ($result !== FALSE) {
if (is_object($result)) {
$i = 0;
$data = array();
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$data[$i] = $row;
$i++;
}
$result->close();
$query = new stdClass();
$query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data;
$query->num_rows = count($data);
unset($data);
return $query;
}
else {
return true;
}
}
else {
trigger_error('Error: ' . $this->mysqli_handler->error . '<br />Error No: ' . $this->mysqli_handler->errno . '<br />' . $sql);
exit();
}
}
public function escape($value) {
return $this->mysqli_handler->real_escape_string($value);
}
public function countAffected() {
return $this->mysqli_handler->affected_rows;
}
public function getLastId() {
return $this->mysqli_handler->insert_id;
}
public function __destruct() {
$this->mysqli_handler->close();
}
}
?>
----------------------------
and this is a
mysqli.php by famous MaxD, created for an OC 1.5.6. parser
define('DB_DRIVER', 'mysqli');
----------------------------
Code: Select all
<?php
final class MySQLi {
private $mysqli;
public function __construct($hostname, $username, $password, $database) {
$this->mysqli = new mysqli($hostname, $username, $password, $database);
if ($this->mysqli->connect_error) {
trigger_error('Error: Could not make a database link (' . $this->mysqli->connect_errno . ') ' . $this->mysqli->connect_error);
}
$this->mysqli->query("SET NAMES 'utf8'");
$this->mysqli->query("SET CHARACTER SET utf8");
$this->mysqli->query("SET CHARACTER_SET_CONNECTION=utf8");
$this->mysqli->query("SET SQL_MODE = ''");
}
public function query($sql) {
$result = $this->mysqli->query($sql);
if ($this->mysqli->errno) {
//$mysqli->errno
}
if (is_resource($resource)) {
$i = 0;
$data = array();
while ($row = $result->fetch_object()) {
$data[$i] = $row;
$i++;
}
$result->close();
$query = new stdClass();
$query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data;
$query->num_rows = $result->num_rows;
unset($data);
return $query;
} else {
return true;
}
} else {
trigger_error('Error: ' . mysql_error($this->link) . '<br />Error No: ' . mysql_errno($this->link) . '<br />' . $sql);
exit();
}
}
public function escape($value) {
return $this->mysqli->real_escape_string($value);
}
public function countAffected() {
return $this->mysqli->affected_rows;
}
public function getLastId() {
return $this->mysqli->insert_id;
}
public function __destruct() {
$this->mysqli->close();
}
}
?>
Good Luck
Ernie
openshop.li