Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PHP Lint Check

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Run PHP linting
run: |
find . -type f -name "*.php" -exec /usr/bin/php -l {} \;
26 changes: 1 addition & 25 deletions dev/test/SENE_Model_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,7 @@ public function invokeMethod(&$object, $methodName, array $parameters = array())
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}

/**
* @uses SENE_Model_Test
* @uses SENE_Model_Mock
* @covers SENE_Model
* @covers SENE_MySQLi_Engine
*/
public function testDBConnection()
{
$tc = new SENE_Model_Mock();
$this->assertEquals(0,$tc->db->__mysqli->connect_errno);
}

/**
* @uses SENE_Model_Test
* @uses SENE_Model_Mock
* @covers SENE_Model
* @covers SENE_MySQLi_Engine
*/
public function testDBError()
{
$tc = new SENE_Model_Mock();
$this->assertEquals(0,$tc->db->__mysqli->errno);
}


/**
* @uses SENE_Model_Test
* @uses SENE_Model_Mock
Expand Down
136 changes: 79 additions & 57 deletions kero/sine/SENE_MySQLi_Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,10 @@ class SENE_MySQLi_Engine

public function __construct()
{
$this->__mysqli = null;
$this->directories = $GLOBALS['SEMEDIR'];
$this->config = $GLOBALS['SEMECFG'];
$port = 3306;
if (isset($this->config->database->port)) {
if (strlen($this->config->database->port)>0) {
$port = $this->config->database->port;
}
}
mysqli_report(MYSQLI_REPORT_STRICT);
$this->__mysqli = new mysqli();
try {
$this->__mysqli->connect($this->config->database->host, $this->config->database->user, $this->config->database->pass, $this->config->database->name, $port);
} catch (mysqli_sql_exception $e) {
if ($this->config->environment == 'development') {
trigger_error(TEM_ERR.': Cannot connect to database server using the supplied settings.', E_USER_ERROR);
throw $e;
} elseif ($this->config->environment == 'staging' && $this->__mysqli->connect_errno) {
header("content-type: application/json");
http_response_code(200);
$data = array();
$data['status'] = $this->__mysqli->connect_errno;
$data['message'] = 'Failed to connect to Database: '.$this->__mysqli->connect_error;
$data['data'] = array();
echo json_encode($data);
return;
}
}

$cs = 'utf8';
if (isset($this->config->database->charset) && strlen($this->config->database->charset)>0) {
$cs = $this->config->database->charset;
}
$this->__mysqli->set_charset($cs);


self::$__instance = $this;

Expand All @@ -102,6 +73,55 @@ public function __construct()
$this->_union_init();
}

private function determine_mysql_port()
{
$this->port = 3306;
if (isset($this->config->database->port)) {
if (strlen($this->config->database->port)>0) {
$this->port = intval($this->config->database->port);
}
}

return $this;
}

protected function set_chartset()
{
$cs = 'utf8';
if (isset($this->config->database->charset) && strlen($this->config->database->charset)>0) {
$cs = $this->config->database->charset;
}
$this->trigger_mysqli()->__mysqli->set_charset($cs);
}

private function trigger_mysqli()
{
if (!isset($this->__mysqli)) {
$this->determine_mysql_port();
mysqli_report(MYSQLI_REPORT_STRICT);
$this->__mysqli = new mysqli();
try {
$this->trigger_mysqli()->__mysqli->connect($this->config->database->host, $this->config->database->user, $this->config->database->pass, $this->config->database->name, $this->port);
} catch (mysqli_sql_exception $e) {
if ($this->config->environment == 'development') {
trigger_error(TEM_ERR.': Cannot connect to database server using the supplied settings.', E_USER_ERROR);
throw $e;
} elseif ($this->config->environment == 'staging' && $this->trigger_mysqli()->__mysqli->connect_errno) {
header("content-type: application/json");
http_response_code(200);
$data = array();
$data['status'] = $this->trigger_mysqli()->__mysqli->connect_errno;
$data['message'] = 'Failed to connect to Database: '.$this->trigger_mysqli()->__mysqli->connect_error;
$data['data'] = array();
echo json_encode($data);
return;
}
}
}

return $this;
}

private function _union_init()
{
$this->union = new stdClass();
Expand All @@ -117,7 +137,7 @@ private function _union_init()

public static function getInstance()
{
return self::$_instance;
return self::$__instance;
}

private function has_bracket_open($bracket_flag)
Expand All @@ -140,41 +160,41 @@ private function has_bracket_close($bracket_flag)

public function autocommit($var=1)
{
return $this->__mysqli->autocommit($var);
return $this->trigger_mysqli()->__mysqli->autocommit($var);
}
public function begin()
{
return $this->__mysqli->begin_transaction();
return $this->trigger_mysqli()->__mysqli->begin_transaction();
}
public function commit()
{
return $this->__mysqli->commit();
return $this->trigger_mysqli()->__mysqli->commit();
}
public function rollback()
{
return $this->__mysqli->rollback();
return $this->trigger_mysqli()->__mysqli->rollback();
}
public function savepoint($sp)
{
return $this->__mysqli->savepoint($sp);
return $this->trigger_mysqli()->__mysqli->savepoint($sp);
}
public function debug($sql='')
{
$this->fieldname[] = 'error';
$this->fieldname[] = 'code';
$this->fieldname[] = 'sql';
$this->fieldvalue[] = $this->__mysqli->errno;
$this->fieldvalue[] = $this->__mysqli->error;
$this->fieldvalue[] = $this->trigger_mysqli()->__mysqli->errno;
$this->fieldvalue[] = $this->trigger_mysqli()->__mysqli->error;
$this->fieldvalue[] = $sql;
}
public function exec($sql)
{
$res = $this->__mysqli->query($sql);
$res = $this->trigger_mysqli()->__mysqli->query($sql);
if ($res) {
return 1;
} else {
if ($this->is_debug) {
trigger_error(TEM_ERR.': '.$this->__mysqli->error.'. '.$sql, E_USER_NOTICE);
trigger_error(TEM_ERR.': '.$this->trigger_mysqli()->__mysqli->error.'. '.$sql, E_USER_NOTICE);
}
return 0;
}
Expand Down Expand Up @@ -228,7 +248,7 @@ public function query($sql, $cache_enabled=0, $flushcache=0, $type="object")
$dataz = json_decode($str);
return $dataz;
} else {
$res = $this->__mysqli->query($sql);
$res = $this->trigger_mysqli()->__mysqli->query($sql);
if ($res) {
$dataz=array();
if ($type=="array") {
Expand All @@ -252,12 +272,12 @@ public function query($sql, $cache_enabled=0, $flushcache=0, $type="object")
return $dataz;
} else {
$this->debug($sql);
trigger_error(TEM_ERR.': '.$this->__mysqli->error.'. '.$sql, E_USER_NOTICE);
trigger_error(TEM_ERR.': '.$this->trigger_mysqli()->__mysqli->error.'. '.$sql, E_USER_NOTICE);
return $this->fieldvalue;
}
}
} else {
$res = $this->__mysqli->query($sql);
$res = $this->trigger_mysqli()->__mysqli->query($sql);
if ($res) {
$dataz=array();
if ($type=="array") {
Expand All @@ -281,7 +301,7 @@ public function query($sql, $cache_enabled=0, $flushcache=0, $type="object")
return $dataz;
} else {
$this->debug($sql);
trigger_error(TEM_ERR.': '.$this->__mysqli->error.'. '.$sql, E_USER_NOTICE);
trigger_error(TEM_ERR.': '.$this->trigger_mysqli()->__mysqli->error.'. '.$sql, E_USER_NOTICE);
return $this->fieldvalue;
}
}
Expand Down Expand Up @@ -325,7 +345,7 @@ public function getStat()
}
public function lastId()
{
return $this->__mysqli->insert_id;
return $this->trigger_mysqli()->__mysqli->insert_id;
}
public function esc($var)
{
Expand All @@ -334,19 +354,19 @@ public function esc($var)
if (strtolower($var)=='null') {
return "NULL";
} else {
return '"'.$this->__mysqli->real_escape_string($var).'"';
return '"'.$this->trigger_mysqli()->__mysqli->real_escape_string($var).'"';
}
}
}
public function __destruct()
{
if (is_resource($this->__mysqli)) {
$this->__mysqli->close();
$this->trigger_mysqli()->__mysqli->close();
}
}
public function getField()
{
return array("field"=>$this->fieldname,"value"=>fieldvalue);
return array("field"=>$this->fieldname,"value"=>$this->fieldvalue);
}

public function where_null($col_params, $operand="AND", $comp="", $bracket=0, $bracket2=0)
Expand Down Expand Up @@ -395,6 +415,7 @@ public function where($params, $params2='', $operand="AND", $comp='=', $bracket=
switch ($comp) {
case "like":
$c= "LIKE";
$val = ''.$v.'';
$val = $this->esc($val);
break;
case 'like%':
Expand All @@ -419,6 +440,7 @@ public function where($params, $params2='', $operand="AND", $comp='=', $bracket=
break;
case "notlike":
$c= "NOT LIKE";
$val = ''.$v.'';
$val = $this->esc($val);
break;
case "notlike%%":
Expand Down Expand Up @@ -628,7 +650,7 @@ public function where_as($params, $params2='', $operand="AND", $comp='=', $brack
switch ($comp) {
case "like":
$c= "LIKE";
$val = ($val);
$val = ($v);
break;
case 'like%':
$c= "LIKE";
Expand All @@ -652,7 +674,7 @@ public function where_as($params, $params2='', $operand="AND", $comp='=', $brack
break;
case "notlike":
$c= "NOT LIKE";
$val = ($val);
$val = ($v);
break;
case "notlike%%":
$c= "NOT LIKE";
Expand Down Expand Up @@ -1166,9 +1188,9 @@ public function flushQuery()
}
public function query_multi($sql)
{
$this->__mysqli->multi_query($sql);
if ($this->__mysqli->errno) {
trigger_error($this->__mysqli->error);
$this->trigger_mysqli()->__mysqli->multi_query($sql);
if ($this->trigger_mysqli()->__mysqli->errno) {
trigger_error($this->trigger_mysqli()->__mysqli->error);
}
}
public function insert_batch($table, $datas=array(), $is_debug=0)
Expand Down Expand Up @@ -1606,17 +1628,17 @@ public function where_in($tbl_key, $values, $is_not=0, $after="AND")

public function getCharSet()
{
$res = $this->__mysqli->character_set_name();
$res = $this->trigger_mysqli()->__mysqli->character_set_name();
if (!$res) {
trigger_error(TEM_ERR.': Cannot get charset from database.');
}
return $res;
}
public function setCharSet($char_set)
{
$res = $this->__mysqli->set_charset($char_set);
$res = $this->trigger_mysqli()->__mysqli->set_charset($char_set);
if (!$res) {
trigger_error(TEM_ERR.': Cant change charset from '.$this->__mysqli->character_set_name().' to '.$char_set.' to database.');
trigger_error(TEM_ERR.': Cant change charset from '.$this->trigger_mysqli()->__mysqli->character_set_name().' to '.$char_set.' to database.');
}
return 1;
}
Expand Down