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;
protected function cryptString(
string $sSource=
""): string|bool
{
if( "" === self::$default_openssl_method )
{
return $sSource;
}
return openssl_encrypt(
$sSource,
self::$default_openssl_method,
self::$db_key,
self::$default_openssl_options,
self::$default_openssl_iv
);
}
{
if( "" === self::$default_openssl_method )
{
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]))
{
}
}
}
} else {
foreach ($aListOfFields as $sFieldname)
{
if (isset($aStorage[$sFieldname]))
{
$aStorage[$sFieldname] = $this->
decryptString($aStorage[$sFieldname]);
}
}
}
return true;
}
string $type,
string $table_name,
array $table_values = [] ,
string $condition = "",
array $aListOfFields = [],
string $key=""
): int
{
if (!is_array($aListOfFields))
{
return 0;
}
foreach ($aListOfFields as $sName)
{
if (isset($table_values[$sName]))
{
$table_values[ $sName ] = $this->
cryptString( $table_values[ $sName ] );
}
}
return $this->build_and_execute(
$type,
$table_name,
$table_values,
$condition,
$key
);
}
public static function __callStatic($method, $args)
{
switch (strtolower($method))
{
case 'cryptstring':
return self::$instance->cryptString($args[0]);
break;
case 'decryptstring':
return self::$instance->decryptString($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="")
secure_build_and_execute(string $type, string $table_name, array $table_values=[], string $condition="", array $aListOfFields=[], string $key="")
trait LEPTON_secure_database
secure_get_one(string $SQL)
decryptString(string $sSource)
setOpenSSLMethod(string $sMethodName)