همونطور که حدس میزدم، کدها نیاز به اصلاحات زیادی داره. امروز یکم وقت کردم یکی از کلاسها رو چک کردم (cls/core_cls_db_mysql.php) و به این شکل تغییرش دادم (از تغییرات در نامگذاری تا روند صدازدن متدها و کامنت گذاری که لازمه کار تیمیه) :
<?php
namespace core\cls\db;
use core\cls\patterns as patterns;
/**
* MySQL DB Wrapper
*/
class MySQL
{
use patterns\singleton;
/**
* @var object The PDO Object
*/
private $pdoObj;
/**
* @var object The PDO statement prepared from the given query
*/
private $query;
/**
* @var resource The result of query execution
*/
private $result;
/**
* Constructor
*/
function __construct()
{
try {
$this->connect();
}
catch(PDOException $e) {
echo 'Error in query execution!<br />Reason: ' . $e->getMessage();
exit;
}
}
/**
* Execute a query
* @param string $query The query to be executed
* @param array $params (Optional) The parameters needed to execute the query
* @return false|resource The query result on success, false otherwise
*/
public function query($query, $params = array())
{
if($this->pdoObj == null) {
$this->connect();
}
try {
if($query == '') {
return false;
}
#perpare query string from security
$this->query = $this->pdoObj->prepare($query);
#going to do query
if(empty($params)) {
$this->result = $this->query->execute();
}
else {
$this->result = $this->query->execute($params);
}
return $this->result;
}
catch(PDOException $e) {
echo 'Error in query execution!<br />Reason: ' . $e->getMessage();
exit;
}
}
/**
* Execute the query with parameter binding based on parameter type
* @param string $query The query to be executed
* @param array $params (Optional) The parameters needed to execute the query
* @return false|resource The query result on success, false otherwise
*/
public function typedQuery($query, $params)
{
if($this->pdoObj == null) {
$this->connect();
}
try {
if($query == '') {
return false;
}
$this->query = $this->pdoObj->prepare($query);
foreach($params as $index => $param) {
$type = ($param[1] == 'integer' ? \PDO::PARAM_INT : \PDO::PARAM_STR);
$this->query->bindValue($index + 1, intval($param[0]), $type);
}
$this->result = $this->query->execute();
}
catch(PDOException $e) {
echo 'Error in query execution!<br />Reason: ' . $e->getMessage();
exit;
}
}
/**
* Get the last auto-increment ID generates for insert queries
* @return int The last ID generated automatically by DB engine
*/
public function lastInsertId()
{
return $this->pdoObj->lastInsertId();
}
/**
* Get the result query as an object
* @return object The result query as an object
*/
public function fetchObject()
{
try {
$result = clone($this->query);
$result->setFetchMode(\PDO::FETCH_OBJ);
return $result;
}
catch(PDOException $e) {
echo 'Error in quary execution!<br />Reason: ' . $e->getMessage();
exit;
}
}
/**
* Get the result query as an associative array
* @return object The result query as an associative array
*/
public function fetchArray()
{
try {
$result = clone($this->query);
$result->setFetchMode(\PDO::FETCH_ASSOC);
return $result->fetchAll();
}
catch(PDOException $e) {
echo 'Error in quary execution!<br />Reason: ' . $e->getMessage();
exit;
}
}
/**
* Get the first row as an associative array
* @return false|array The first row as an associative array
*/
public function queryOne()
{
$result = $this->fetchArray();
return (count($result) > 0 ? $result[0] : false);
}
#ths function return number of rows that return in last query
/**
* Get the row count of the last executed query
* @return false|integer The row count on successful query execution, false otherwise
*/
public function rowCount()
{
if($this->query) {
return false;
}
return $this->query->rowCount();
}
//this function create pdo_obj to database
/**
* Connect to DB engine
*/
private function connect()
{
$options = array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'utf8\'');
$this->pdoObj = new \PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME , DB_USER, DB_PASS, $options);
$this->pdoObj->setAttribute( \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION );
}
/**
* Disconnect from DB engine
*/
private function disconnect()
{
$this->pdoObj = null;
$this->query = null;
}
/**
* Export the database
* @return int The result of export operation (0: success, 1: warning, 2:error)
*/
public function export()
{
$command = 'mysqldump --opt -h ' . DB_HOST .' -u ' . DB_USER .' -p ' . DB_PASS . ' ' . DB_NAME .' > ' . AppPath . 'upload/buffer/database.sql';
$output = array();
exec($command, $output, $result);
return $result;
}
/**
* Import the database
* @param string $filename
* @return int The result of export operation (0: success, 1: warning, 2:error)
*/
public function import($filename)
{
if(!file_exists($filename)) {
return false;
}
$command = 'mysql -h ' . DB_HOST . ' -u ' . DB_USER . ' -p ' . DB_PASS . ' ' . DB_NAME . ' < ' . $filename;
$output = array();
exec($command, $output, $result);
return $result;
}
}
این کد رو با نسخه ای که خودتون گذاشتین مقایسه کنید و بقیه کلاسها رو هم به همین شکل مستندسازی کنید.