upgrade on mysqlmanager
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
/**
|
||||
* Manage includes
|
||||
* @author franzz
|
||||
* @version 1.0
|
||||
*/
|
||||
class ClassManagement extends PhpObject
|
||||
{
|
||||
@@ -15,7 +16,7 @@ class ClassManagement extends PhpObject
|
||||
|
||||
function __construct($sMainClass)
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct(__CLASS__, true);
|
||||
$this->asIncFiles = array();
|
||||
|
||||
//try to include default files
|
||||
@@ -61,9 +62,9 @@ class ClassManagement extends PhpObject
|
||||
}
|
||||
|
||||
/**
|
||||
* PhpObject
|
||||
*
|
||||
* @author franzz
|
||||
* @version 1.0
|
||||
* @version 1.0a
|
||||
*/
|
||||
class PhpObject
|
||||
{
|
||||
@@ -85,15 +86,27 @@ class PhpObject
|
||||
//Class variables
|
||||
private $asMessageStack;
|
||||
private $iExtractMode;
|
||||
protected $bDebug;
|
||||
private $sChildClass;
|
||||
private $bDebug;
|
||||
|
||||
function __construct($iExtractMode=self::MODE_FILE)
|
||||
function __construct($sClass='', $bDebug=false, $iExtractMode=self::MODE_FILE)
|
||||
{
|
||||
$this->resetMessageStack();
|
||||
$this->setDebug($bDebug);
|
||||
$this->iExtractMode = $iExtractMode;
|
||||
$this->bDebug = false;
|
||||
$this->sChildClass = $sClass;
|
||||
}
|
||||
|
||||
public function setDebug($bDebug)
|
||||
{
|
||||
$this->bDebug = $bDebug;
|
||||
}
|
||||
|
||||
public function getDebug()
|
||||
{
|
||||
return $this->bDebug;
|
||||
}
|
||||
|
||||
private static function getLogPath()
|
||||
{
|
||||
return dirname(__FILE__).'/'.self::LOG_FILENAME;
|
||||
@@ -140,6 +153,28 @@ class PhpObject
|
||||
|
||||
return $this->glueMessages($asMessages);
|
||||
}
|
||||
|
||||
protected function cleanMessageStack()
|
||||
{
|
||||
$sErrorStack = $this->getCleanMessageStack($this->getDebug()?self::ALL_TAB:self::ERROR_TAB);
|
||||
if($sErrorStack!='')
|
||||
{
|
||||
switch($this->iExtractMode)
|
||||
{
|
||||
case self::MODE_TEXT:
|
||||
echo $sErrorStack;
|
||||
break;
|
||||
case self::MODE_HTML:
|
||||
echo $sErrorStack;
|
||||
break;
|
||||
case self::MODE_ARRAY:
|
||||
break;
|
||||
case self::MODE_FILE:
|
||||
@file_put_contents(self::getLogPath(), "\n\n".$this->sChildClass.' - '.date('r')."\n".$sErrorStack, FILE_APPEND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCleanMessageStacks($aoExtsources, $sType=self::ALL_TAB)
|
||||
{
|
||||
@@ -202,24 +237,7 @@ class PhpObject
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
$sErrorStack = $this->getCleanMessageStack($this->bDebug?self::ALL_TAB:self::ERROR_TAB);
|
||||
if($sErrorStack!='')
|
||||
{
|
||||
switch($this->iExtractMode)
|
||||
{
|
||||
case self::MODE_TEXT:
|
||||
echo $sErrorStack;
|
||||
break;
|
||||
case self::MODE_HTML:
|
||||
echo $sErrorStack;
|
||||
break;
|
||||
case self::MODE_ARRAY:
|
||||
break;
|
||||
case self::MODE_FILE:
|
||||
@file_put_contents(self::getLogPath(), "\n\n".date('r')."\n".$sErrorStack, FILE_APPEND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->cleanMessageStack();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ class MySqlManager extends PhpObject
|
||||
|
||||
public $sDbState;
|
||||
private $bTrace;
|
||||
private $asOptions;
|
||||
|
||||
/**
|
||||
* SQL connection Handle
|
||||
@@ -21,19 +20,15 @@ class MySqlManager extends PhpObject
|
||||
*/
|
||||
private $oConnection;
|
||||
private $sDatabase;
|
||||
|
||||
private $asOptions;
|
||||
|
||||
/**
|
||||
* Constructor MySqlManager
|
||||
* @param String $sDbServer
|
||||
* @param String $sLogin
|
||||
* @param String $sPass
|
||||
* @param String $sDatabase
|
||||
* @param Array $asOptions
|
||||
* array( 'tables'=>array('table_name1'=>array('table_field1', 'table_field2', ...), 'table_name2'=>array(...)),
|
||||
* Tables & fields descriptions
|
||||
* array( 'tables'=>array('table_name1'=>array('table_field1', 'table_field2', ...), 'table_name2'=>array(...)),
|
||||
* 'types'=>array('field1'=>'field_type1', 'field2'=>'field_type2', ...)
|
||||
* 'constraints'=>array('table_name1'=>'table_contraint1', 'table_name2'=>'table_contraint2', ...),
|
||||
* 'cascading_delete'=>array('table_name1'=>array('linked_table1', 'linked_table2', ...), 'table_name2'=>...))
|
||||
* @param string $sEncoding
|
||||
* @var Array
|
||||
*/
|
||||
public function __construct($sDbServer, $sLogin, $sPass, $sDatabase, $asOptions, $sEncoding='utf8mb4')
|
||||
{
|
||||
@@ -51,16 +46,13 @@ class MySqlManager extends PhpObject
|
||||
*/
|
||||
|
||||
$this->setTrace(false);
|
||||
//if(!$this->oConnection)
|
||||
if($this->oConnection->connect_error)
|
||||
{
|
||||
//$this->addError('bug connection');
|
||||
$this->addError('bug connection : '.$this->oConnection->connect_error);
|
||||
$this->sDbState = self::DB_NO_CONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if(!mysql_select_db($this->sDatabase, $this->oConnection))
|
||||
if(!$this->oConnection->select_db($this->sDatabase))
|
||||
{
|
||||
$this->addError('bug selecting database. Installing...');
|
||||
@@ -88,31 +80,22 @@ class MySqlManager extends PhpObject
|
||||
public function __destruct()
|
||||
{
|
||||
parent::__destruct();
|
||||
//mysql_close($this->oConnection);
|
||||
$this->oConnection->close();
|
||||
}
|
||||
|
||||
public function setTrace($bAction)
|
||||
public function setTrace($bTrace)
|
||||
{
|
||||
$this->bTrace = $bAction;
|
||||
$this->bTrace = $bTrace;
|
||||
if($bTrace) $this->setDebug(true);
|
||||
}
|
||||
|
||||
public function getTrace()
|
||||
{
|
||||
return $this->bTrace;
|
||||
}
|
||||
|
||||
public function getTables()
|
||||
{
|
||||
/*
|
||||
$oReflect = new ReflectionClass(__CLASS__);
|
||||
$asConstants = $oReflect->getConstants();
|
||||
$sTableTag = '_TABLE';
|
||||
$asTables = array();
|
||||
foreach($asConstants as $sConstant=>$sConstantValue)
|
||||
{
|
||||
if(mb_strpos($sConstant, $sTableTag)!==false && mb_strpos($sConstant, $sTableTag)==(mb_strlen($sConstant) - mb_strlen($sTableTag)))
|
||||
{
|
||||
$asTables[] = $sConstantValue;
|
||||
}
|
||||
}
|
||||
return $asTables;
|
||||
*/
|
||||
return array_keys($this->asOptions['tables']);
|
||||
}
|
||||
|
||||
@@ -121,7 +104,6 @@ class MySqlManager extends PhpObject
|
||||
//Create Database
|
||||
$this->setQuery("DROP DATABASE IF EXISTS ".$this->sDatabase);
|
||||
$this->setQuery("CREATE DATABASE ".$this->sDatabase." DEFAULT CHARACTER SET ".Settings::DB_ENC." DEFAULT COLLATE ".Settings::DB_ENC."_general_ci");
|
||||
//mysql_select_db($this->sDatabase, $this->oConnection);
|
||||
$this->oConnection->select_db($this->sDatabase);
|
||||
|
||||
//Create tables
|
||||
@@ -171,31 +153,25 @@ class MySqlManager extends PhpObject
|
||||
private function setQuery($sQuery, $sTypeQuery=__FUNCTION__)
|
||||
{
|
||||
$this->getQuery($sQuery, $sTypeQuery);
|
||||
//return (mysql_affected_rows()!=0);
|
||||
return ($this->oConnection->affected_rows!=0);
|
||||
}
|
||||
|
||||
private function getQuery($sQuery, $sTypeQuery=__FUNCTION__)
|
||||
{
|
||||
$sQuery = str_replace(array("\n", "\t"), array(" ", ""), $sQuery);
|
||||
//$oResult = mysql_query($sQuery, $this->oConnection);
|
||||
|
||||
if($this->bTrace)
|
||||
{
|
||||
$this->setDebug(true);
|
||||
$this->addNotice($sQuery);
|
||||
}
|
||||
if($this->getTrace()) $this->addNotice($sQuery);
|
||||
|
||||
if(!($oResult = $this->oConnection->query($sQuery)))
|
||||
{
|
||||
$this->addError("\nErreur SQL : \n".str_replace("\t", "", $sQuery)."\n\n".str_replace(array("\t", "\n"), "", $this->oConnection->error));
|
||||
$this->addError("\nErreur SQL : \n".str_replace("\t", "", $sQuery)."\n\n".str_replace(array("\t", "\n"), "", $this->getLastError()));
|
||||
}
|
||||
return $oResult;
|
||||
}
|
||||
|
||||
public function getLastError()
|
||||
{
|
||||
|
||||
return $this->oConnection->error;
|
||||
}
|
||||
|
||||
public function getArrayQuery($sQuery, $bStringOnly=false, $sGroupBy='', $sTypeQuery=__FUNCTION__)
|
||||
@@ -206,7 +182,6 @@ class MySqlManager extends PhpObject
|
||||
$oResult = $this->getQuery($sQuery, true, $sTypeQuery);
|
||||
if($oResult!==false)
|
||||
{
|
||||
//while($asCurrentRow = mysql_fetch_array($oResult))
|
||||
while($asCurrentRow = $oResult->fetch_array())
|
||||
{
|
||||
if($bStringOnly) $asCurrentRow = $this->arrayKeyFilter($asCurrentRow, 'is_string');
|
||||
@@ -444,7 +419,24 @@ class MySqlManager extends PhpObject
|
||||
$this->setQuery("DELETE FROM ".$sTable." WHERE ".$this->getId($sTableName)." = ".$iTableId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function emptyTable($sTableName)
|
||||
{
|
||||
$this->cleanSql($sTableName);
|
||||
return $this->setQuery("TRUNCATE ".$sTableName);
|
||||
}
|
||||
|
||||
public function selectList($sTableName, $sColumnName='', $asConstraints=array())
|
||||
{
|
||||
$sColumnName = $sColumnName==''?self::getText($sTableName):$sColumnName;
|
||||
$sIdColumnName = self::getId($sTableName);
|
||||
return $this->selectRows( array( 'select' => array($sIdColumnName, $sColumnName),
|
||||
'from' => $sTableName,
|
||||
'constraint'=> $asConstraints),
|
||||
true,
|
||||
$sIdColumnName);
|
||||
}
|
||||
|
||||
public function selectRows($asInfo, $bStringOnly=true, $sGroupBy='')
|
||||
{
|
||||
$asAttributes = array('select'=>"SELECT", 'from'=>"FROM", 'join'=>"LEFT JOIN", 'joinOn'=>"LEFT JOIN", 'constraint'=>"WHERE", 'groupBy'=>"GROUP BY", 'orderBy'=>"ORDER BY", 'limit'=>'LIMIT');
|
||||
@@ -452,7 +444,6 @@ class MySqlManager extends PhpObject
|
||||
$asOperators = array('constraint'=>" = ", 'orderBy'=>" ", 'join'=>" USING(", 'joinOn'=>" ON ");
|
||||
$asEndOfStatement = array('constraint'=>"", 'orderBy'=>"", 'join'=>")", 'joinOn'=>"");
|
||||
|
||||
//$sQuery = "/* ".str_replace(array("\n", "\t"), '', print_r($asInfo, true))." */";
|
||||
$sQuery = "";
|
||||
foreach($asAttributes as $sStatement => $sKeyWord)
|
||||
{
|
||||
@@ -482,6 +473,15 @@ class MySqlManager extends PhpObject
|
||||
{
|
||||
$asOperators[$sStatement] = $asInfo['constOpe'];
|
||||
}
|
||||
elseif($sStatement=='joinOn')
|
||||
{
|
||||
$asSimplifiedSelection = array();
|
||||
foreach($asSelection as $sTable => $asJoinFields)
|
||||
{
|
||||
$asSimplifiedSelection[$sTable] = $this->implodeAll($asJoinFields, " = ", " AND ", $sTable.".", ".[/KEY\]");
|
||||
}
|
||||
$asSelection = $asSimplifiedSelection;
|
||||
}
|
||||
$sQuery .= $this->implodeAll($asSelection, $asOperators[$sStatement], $asRowSeparators[$sStatement], "", $asEndOfStatement[$sStatement]);
|
||||
}
|
||||
else
|
||||
@@ -500,7 +500,7 @@ class MySqlManager extends PhpObject
|
||||
|
||||
private function addColumnSelectors(&$asSelection)
|
||||
{
|
||||
//TODO get rid of this
|
||||
//FIXME get rid of this
|
||||
$sSqlWord = 'option';
|
||||
$sKey = array_search($sSqlWord, $asSelection);
|
||||
if($sKey!==false)
|
||||
@@ -516,21 +516,22 @@ class MySqlManager extends PhpObject
|
||||
|
||||
public function selectRow($sTableName, $asConstraints=array(), $sColumnName='*')
|
||||
{
|
||||
if(!is_array($asConstraints))
|
||||
{
|
||||
$asConstraints = array($this->getId($sTableName)=>$asConstraints);
|
||||
}
|
||||
$asResult = $this->selectRows(array('select'=>$sColumnName, 'from'=>$sTableName, 'constraint'=>$asConstraints));
|
||||
$iCountNb = count($asResult);
|
||||
//Table ID directly
|
||||
if(!is_array($asConstraints)) $asConstraints = array($this->getId($sTableName)=>$asConstraints);
|
||||
|
||||
$asRows = $this->selectRows(array('select'=>$sColumnName, 'from'=>$sTableName, 'constraint'=>$asConstraints));
|
||||
$iCountNb = count($asRows);
|
||||
switch($iCountNb)
|
||||
{
|
||||
case 0 :
|
||||
return false;
|
||||
$asResult = array();
|
||||
break;
|
||||
case $iCountNb > 1 :
|
||||
$this->addError('Trop de résultats pour un selectRow() : '.$iCountNb.' lignes. Table: '.$sTableName.', contrainte: '.self::implodeAll($asConstraints, '=', ' ').', colonne: '.$sColumnName);
|
||||
break;
|
||||
default:
|
||||
$asResult = array_shift($asRows);
|
||||
}
|
||||
return array_shift($asResult);
|
||||
return $asResult;
|
||||
}
|
||||
|
||||
public function selectValue($sTableName, $sColumnName, $oConstraints=array())
|
||||
@@ -539,7 +540,8 @@ class MySqlManager extends PhpObject
|
||||
{
|
||||
$oConstraints = array($this->getId($sTableName)=>$oConstraints);
|
||||
}
|
||||
return $this->selectRow($sTableName, $oConstraints, $sColumnName);
|
||||
$oResult = $this->selectRow($sTableName, $oConstraints, $sColumnName);
|
||||
return empty($oResult)?false:$oResult;
|
||||
}
|
||||
|
||||
public function pingValue($sTableName, $oConstraints)
|
||||
@@ -549,12 +551,11 @@ class MySqlManager extends PhpObject
|
||||
|
||||
public function cleanSql(&$oData)
|
||||
{
|
||||
//self::cleanData($oData, 'mysql_real_escape_string');
|
||||
//$oData = self::cleanData($oData, 'mysql_real_escape_string');
|
||||
$this->cleanData($oData);
|
||||
$oData = $this->cleanData($oData);
|
||||
}
|
||||
|
||||
//TODO déplacer dans ToolBox::implodeAll
|
||||
public static function implodeAll($asText, $asKeyValueSeparator='', $sRowSeparator='', $sKeyPre='', $sValuePost=false)
|
||||
{
|
||||
if($sValuePost===false)
|
||||
@@ -569,9 +570,14 @@ class MySqlManager extends PhpObject
|
||||
$asKeyValueSeparator = array_combine(array_keys($asText), array_fill(0, count($asText), $asKeyValueSeparator));
|
||||
}
|
||||
|
||||
$asFrom = array('[/KEY\]', '[/VALUE\]');
|
||||
foreach($asText as $sKey=>$sValue)
|
||||
{
|
||||
$asCombinedText[] = $sKeyPre.$sKey.$asKeyValueSeparator[$sKey].(is_array($sValue)?implode($sValue):$sValue).$sValuePost;
|
||||
$asTo = array($sKey, $sValue);
|
||||
$sRepKeyPre = str_replace($asFrom, $asTo, $sKeyPre);
|
||||
$asRepKeyValueSeparator = str_replace($asFrom, $asTo, $asKeyValueSeparator[$sKey]);
|
||||
$sRepValuePost = str_replace($asFrom, $asTo, $sValuePost);
|
||||
$asCombinedText[] = $sRepKeyPre.$sKey.$asRepKeyValueSeparator.(is_array($sValue)?implode($sValue):$sValue).$sRepValuePost;
|
||||
}
|
||||
return implode($sRowSeparator, $asCombinedText);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
//Start buffering
|
||||
ob_start();
|
||||
require_once 'config.php';
|
||||
require_once 'class_management.php';
|
||||
$oClassManagement = new ClassManagement('main');
|
||||
ToolBox::cleanPost($_POST);
|
||||
ToolBox::cleanPost($_GET);
|
||||
|
||||
20
standalone/build_random_pic_file.php
Executable file
20
standalone/build_random_pic_file.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
$sOutFilePath = 'logo_givaudan_48.php';
|
||||
|
||||
$asResult[] = '<?php';
|
||||
$asResult[] = '';
|
||||
foreach (glob("resize/*_48.png") as $sFileName)
|
||||
{
|
||||
$sImageString = base64_encode(file_get_contents($sFileName));
|
||||
$asImages[] = '\''.str_replace("'", "\'", $sImageString).'\'';
|
||||
}
|
||||
$asResult[] = '$asImages = array('."\t".implode(', '."\n\t\t\t\t\t", $asImages).');';
|
||||
$asResult[] = '';
|
||||
$asResult[] = 'header(\'Content-Type: image/png\');';
|
||||
$asResult[] = 'echo base64_decode($asImages[rand(0, count($asImages)-1)]);';
|
||||
$asResult[] = "\n\n".'?>';
|
||||
|
||||
file_put_contents($sOutFilePath, implode("\n", $asResult));
|
||||
chmod($sOutFilePath, 0777);
|
||||
?>
|
||||
Reference in New Issue
Block a user