Public "shortcut" for executing a single mySql-query without passing values.
<?php
declare(strict_types=1);
{
static private string $db_key = "";
static private string $default_openssl_method = "";
static private string $default_openssl_iv = "";
static private string $default_openssl_ivlen = "";
static private int $default_openssl_options = 0;
private bool $bOpenSslInstalled = false;
protected function cryptString(
string $sSource=
""): string|bool
{
if( false === $this->bOpenSslInstalled )
{
return $sSource;
}
return openssl_encrypt(
$sSource,
self::$default_openssl_method,
self::$db_key,
self::$default_openssl_options,
self::$default_openssl_iv
);
}
{
if ((false === $this->bOpenSslInstalled) || ("" === $sSource))
{
return $sSource;
}
return openssl_decrypt(
$sSource,
self::$default_openssl_method,
self::$db_key,
self::$default_openssl_options,
self::$default_openssl_iv
);
}
{
self::$default_openssl_method = $sMethodName;
}
{
self::$default_openssl_iv = $sNewIV;
}
{
$result = $this->get_one($SQL);
return (is_null($result))
? NULL
;
}
string $aQuery = "",
bool $bFetch = false,
array &$aStorage = array(),
bool $bFetchAll = true,
array $aListOfFields = array()
): bool
{
if (!is_array($aListOfFields))
{
return false;
}
$result = $this->execute_query(
$aQuery,
$bFetch,
$aStorage,
$bFetchAll
);
if (false === $result)
{
return false;
}
if (true === $bFetchAll)
{
foreach ($aStorage as &$ref)
{
foreach ($aListOfFields as $sFieldname)
{
if (isset($ref[$sFieldname]))
{
$ref[$sFieldname] = $this->
decryptString( (
string)$ref[$sFieldname]);
}
}
}
} else {
foreach ($aListOfFields as $sFieldname)
{
if (isset($aStorage[$sFieldname]))
{
$aStorage[$sFieldname] = $this->
decryptString( (
string)$aStorage[$sFieldname]);
}
}
}
return true;
}
string $type,
string $table_name,
array $table_values = [] ,
string $condition = "",
array $aListOfFields = [],
bool $display_query = false
): int
{
if (!is_array($aListOfFields))
{
return 0;
}
foreach ($aListOfFields as $sName)
{
if (isset($table_values[$sName]))
{
$table_values[ $sName ] = $this->
cryptString( (
string)$table_values[$sName]);
}
}
return $this->build_and_execute(
$type,
$table_name,
$table_values,
$condition,
$display_query
);
}
public static function __callStatic($method, $args)
{
switch (strtolower($method))
{
case 'cryptstring':
return self::$instance->cryptString((string)$args[0]);
break;
case 'decryptstring':
return self::$instance->decryptString((string)$args[0]);
break;
default:
return NULL;
break;
}
}
}
setOpenSSLIv(string $sNewIV)
secure_execute_query(string $aQuery="", bool $bFetch=false, array &$aStorage=array(), bool $bFetchAll=true, array $aListOfFields=array())
cryptString(string $sSource="")
trait LEPTON_secure_database
secure_get_one(string $SQL)
decryptString(string $sSource)
setOpenSSLMethod(string $sMethodName)
secure_build_and_execute(string $type, string $table_name, array $table_values=[], string $condition="", array $aListOfFields=[], bool $display_query=false)