1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00
This commit is contained in:
DanieL 2022-08-11 17:04:52 -03:00
parent e81ee866ad
commit fc3bfefaf8

View file

@ -1,4 +1,5 @@
<?php
/*
tester-execution-code
$sql = "SELECT * FROM users WHERE id=?;";
@ -18,11 +19,12 @@
* Internal used class
*/
class iimysqli_result
{
class iimysqli_result {
public $stmt;
public $nCols;
public $fields;
}
global $disableMysqlNdMethods;
@ -34,10 +36,9 @@ $disableMysqlNdMethods = false;
* It wouldn't be possible without Daan on https://stackoverflow.com/questions/31562359/workaround-for-mysqlnd-missing-driver
*/
class sqlDAL
{
public static function executeFile($filename)
{
class sqlDAL {
public static function executeFile($filename) {
global $global;
$templine = '';
// Read in entire file
@ -71,8 +72,7 @@ class sqlDAL
* @return boolean true on success, false on fail
*/
public static function writeSql($preparedStatement, $formats = "", $values = [])
{
public static function writeSql($preparedStatement, $formats = "", $values = []) {
global $global, $disableMysqlNdMethods;
if (empty($preparedStatement)) {
return false;
@ -95,9 +95,9 @@ class sqlDAL
}
if (!($stmt = $global['mysqli']->prepare($preparedStatement))) {
log_error("[sqlDAL::writeSql] Prepare failed: (" . $global['mysqli']->errno . ") " . $global['mysqli']->error .
" preparedStatement = ". json_encode($preparedStatement).
" formats = ". json_encode($formats));
log_error("[sqlDAL::writeSql] Prepare failed: (" . $global['mysqli']->errno . ") " . $global['mysqli']->error .
" preparedStatement = " . json_encode($preparedStatement) .
" formats = " . json_encode($formats));
return false;
}
//var_dump($preparedStatement, $formats, $values);exit;
@ -109,7 +109,7 @@ class sqlDAL
$stmt->execute();
} catch (Exception $exc) {
log_error($exc->getTraceAsString());
log_error('Error in writeSql stmt->execute: '.$preparedStatement);
log_error('Error in writeSql stmt->execute: ' . $preparedStatement);
}
if ($stmt->errno !== 0) {
@ -136,8 +136,7 @@ class sqlDAL
* @return Object Depend if mysqlnd is active or not, a object, but always false on fail
*/
public static function readSql($preparedStatement, $formats = "", $values = [], $refreshCache = false)
{
public static function readSql($preparedStatement, $formats = "", $values = [], $refreshCache = false) {
// $refreshCache = true;
global $global, $disableMysqlNdMethods, $readSqlCached, $crc;
// need to add dechex because some times it return an negative value and make it fails on javascript playlists
@ -156,22 +155,24 @@ class sqlDAL
$readSqlCached[$crc] = "false";
_mysql_connect();
if (!($stmt = $global['mysqli']->prepare($preparedStatement))) {
log_error("[sqlDAL::readSql] (mysqlnd) Prepare failed: ({$global['mysqli']->errno}) ({$global['mysqli']->error}) ".
" preparedStatement = ". json_encode($preparedStatement).
" formats = ". json_encode($formats).
" values = ". json_encode($values).
" refreshCache = ". json_encode($refreshCache).
" stmt = ". json_encode($stmt));
try {
$stmt = $global['mysqli']->prepare($preparedStatement);
} catch (Exception $exc) {
log_error("[sqlDAL::readSql] (mysqlnd) Prepare failed: ({$global['mysqli']->errno}) ({$global['mysqli']->error}) " .
" preparedStatement = " . json_encode($preparedStatement) .
" formats = " . json_encode($formats) .
" values = " . json_encode($values) .
" refreshCache = " . json_encode($refreshCache) .
" stmt = " . json_encode($stmt));
//log_error("[sqlDAL::readSql] trying close and reconnect");
_mysql_close();
_mysql_connect();
if (!($stmt = $global['mysqli']->prepare($preparedStatement))) {
try {
$stmt = $global['mysqli']->prepare($preparedStatement);
log_error("[sqlDAL::readSql] SUCCESS close and reconnect works!");
} catch (Exception $exc) {
log_error("[sqlDAL::readSql] (mysqlnd) Prepare failed again return false");
return false;
} else {
log_error("[sqlDAL::readSql] SUCCESS close and reconnect works!");
}
}
if (!sqlDAL::eval_mysql_bind($stmt, $formats, $values)) {
@ -255,8 +256,7 @@ class sqlDAL
* @param Object $result A object from sqlDAL::readSql
*/
public static function close($result)
{
public static function close($result) {
global $disableMysqlNdMethods, $global;
if ((!function_exists('mysqli_fetch_all')) || ($disableMysqlNdMethods !== false)) {
if (!empty($result->stmt)) {
@ -271,8 +271,7 @@ class sqlDAL
* @return int The nr of rows
*/
public static function num_rows($res)
{
public static function num_rows($res) {
global $global, $disableMysqlNdMethods, $crc, $num_row_cache;
if (!isset($num_row_cache)) {
$num_row_cache = [];
@ -295,8 +294,7 @@ class sqlDAL
}
// unused
public static function cached_num_rows($data)
{
public static function cached_num_rows($data) {
return sizeof($data);
}
@ -306,8 +304,7 @@ class sqlDAL
* @return array A array filled with all rows as a assoc array
*/
public static function fetchAllAssoc($result)
{
public static function fetchAllAssoc($result) {
global $crc, $fetchAllAssoc_cache;
if (!isset($fetchAllAssoc_cache)) {
$fetchAllAssoc_cache = [];
@ -328,8 +325,7 @@ class sqlDAL
* @return int A single row in a assoc array
*/
public static function fetchAssoc($result)
{
public static function fetchAssoc($result) {
global $global, $disableMysqlNdMethods;
ini_set('memory_limit', '-1');
// here, a cache is more/too difficult, because fetch gives always a next. with this kind of cache, we would give always the same.
@ -349,8 +345,7 @@ class sqlDAL
* @return array A array filled with all rows
*/
public static function fetchAllArray($result)
{
public static function fetchAllArray($result) {
global $crc, $fetchAllArray_cache;
if (!isset($fetchAllArray_cache)) {
$fetchAllArray_cache = [];
@ -374,8 +369,7 @@ class sqlDAL
* @return int A single row in a array
*/
public static function fetchArray($result)
{
public static function fetchArray($result) {
global $global, $disableMysqlNdMethods;
if ((function_exists('mysqli_fetch_all')) && ($disableMysqlNdMethods == false)) {
return $result->fetch_array();
@ -385,8 +379,7 @@ class sqlDAL
return false;
}
private static function eval_mysql_bind($stmt, $formats, $values)
{
private static function eval_mysql_bind($stmt, $formats, $values) {
if (($stmt->param_count != sizeof($values)) || ($stmt->param_count != strlen($formats))) {
return false;
}
@ -404,8 +397,7 @@ class sqlDAL
return true;
}
private static function iimysqli_stmt_get_result($stmt)
{
private static function iimysqli_stmt_get_result($stmt) {
global $global;
$metadata = mysqli_stmt_result_metadata($stmt);
$ret = new iimysqli_result();
@ -432,8 +424,7 @@ class sqlDAL
return $ret;
}
private static function iimysqli_result_fetch_assoc(&$result)
{
private static function iimysqli_result_fetch_assoc(&$result) {
global $global;
$ret = [];
$code = "return mysqli_stmt_bind_result(\$result->stmt ";
@ -452,8 +443,7 @@ class sqlDAL
return $ret;
}
private static function iimysqli_result_fetch_array(&$result)
{
private static function iimysqli_result_fetch_array(&$result) {
$ret = [];
$code = "return mysqli_stmt_bind_result(\$result->stmt ";
@ -470,14 +460,14 @@ class sqlDAL
};
return $ret;
}
}
function log_error($err)
{
function log_error($err) {
if (!empty($global['debug']) || isCommandLineInterface()) {
echo $err;
}
_error_log("MySQL ERROR: ".json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5)), AVideoLog::$ERROR);
_error_log("MySQL ERROR: " . json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5)), AVideoLog::$ERROR);
_error_log($err, AVideoLog::$ERROR);
}