Enter description here...

@param DbDataSet $dbdata
@param string $desc
@param string $sql
@return unknown
768933
protected function CreateTable($dbdata, $desc, $sql)
	{
		$result = $desc. ": ";
		try 
		{
			$dbdata->execSQL($sql);
			$result .= "OK";
		}
		catch (Exception $ex)
		{
			$result .= $this->myWords->Value("GOTERROR", $ex->getMessage());
		}
		return $result;
	}
996562
public function query(string $sql, $data = null) {
		$connection = $this->pool->getConnection();
		$result = null;
		$tryAgain = true;
SQL_START_EXECUTE:
		if (is_array($data) && count($data) > 0) {
			if (strpos($sql, ':') !== false) {
				$bind = [];
				$sql = preg_replace_callback('/:(\w+)\b/', function ($matches) use (&$data, &$bind) {
					$bind[] = $data[$matches[1]];
					return '?';
				}, $sql);
				$data = &$bind;
			}
			try {
				$st = $connection->prepare($sql);
				if ($st === false) {
					goto SQL_TRY_AGAIN;
				}
				if (is_object($st)) {
					$result = $st->execute($data);
				} else {
					$result = $connection->execute($data);
				}
			} catch (\Throwable $e) {
				goto SQL_TRY_AGAIN;
			}
			if ($result === false) {
				goto SQL_TRY_AGAIN;
			}
			goto SQL_SUCCESS_RETURN;
		} else {
			try {
				$result = $connection->query($sql);
			} catch (\Throwable $e) {
				goto SQL_TRY_AGAIN;
			}
			if ($result === false) {
				goto SQL_TRY_AGAIN;
			}
			goto SQL_SUCCESS_RETURN;
		}
SQL_TRY_AGAIN:
		if (($connection->errno === 2006 || $connection->errno === 2013) && $tryAgain) {
			$tryAgain = false;
			$connection = $this->pool->reconnect($connection);
			goto SQL_START_EXECUTE;
		} else {
			$error = $connection->error;
			$errno = $connection->errno;
			$this->pool->freeConnection($connection);
			throw new DBException($error, $errno);
		}
SQL_SUCCESS_RETURN:
		if ($result === true) {
			$result = [
				'_affected_rows' => $connection->affected_rows
			];
			if (stripos($sql, 'insert') === 0) {
				$result['_insert_id'] = $connection->insert_id;
			}
		}
		$this->pool->freeConnection($connection);
		return $result;
	}
1028364
public static function insert($sqlstatement, array $data = [])
    {
        static::verifyConnection();

        if (!preg_match(
            "/^insert\s+into\s+[\w\d_-`]+\s?(\(.+\))?\s+(values\s?(\(.+\),?)+|\s?set\s+(.+)+);?$/i",
            $sqlstatement
        )) {
            throw new DatabaseException(
                'Syntax Error on the Request',
                E_USER_ERROR
            );
        }

        if (empty($data)) {
            $pdoStement = static::$adapter->getConnection()->prepare($sqlstatement);

            $pdoStement->execute();

            return $pdoStement->rowCount();
        }

        $collector = [];
        
        $r = 0;

        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $r += static::executePrepareQuery($sqlstatement, $value);

                continue;
            }

            $collector[$key] = $value;
        }

        if (!empty($collector)) {
            return static::executePrepareQuery($sqlstatement, $collector);
        }

        return $r;
    }
1362437
public static function update($sqlstatement, array $data = [])
    {
        static::verifyConnection();

        if (preg_match("/^update\s[\w\d_`]+\s\bset\b\s.+\s\bwhere\b\s.+$/i", $sqlstatement)) {
            return static::executePrepareQuery($sqlstatement, $data);
        }

        return false;
    }
902071
public function execute( $query, array $data = [ ] )
    {
        $result = NULL;

        $statement = $this->database->prepare( $query );

        if ( FALSE === $statement )
        {
            $this->close();

            throw new DatabaseException( 'Failed to create prepared statement.' );
        }

        $result = $statement->execute( $data );

        $this->query = $statement->queryString;

        if ( FALSE !== $result )
        {
            $result = ( int ) $statement->rowCount();
        }

        return $result;
    }
1014093
public function query(string $sql, array $params = [], bool $unbuffered = false) : AbstractResult
    {
        if ($this->connected == false) {
            $this->connect();
        }

        $event = new TimerEvent('db.query');

        $finalQuery = $this->getFinalQuery($sql, $params);
        try {
            $result = $this->execute($finalQuery, $unbuffered);
        } catch (QueryException $exception) {
            $this->emitQueryEvent($event, null, $sql);
            throw $exception;
        }

        $this->emitQueryEvent($event, $result);

        return $result;
    }
427145
public function move($dest)
    { 
		$tree = new CDBTree('dir_structure');
        $prntid = self::getDbConnection()->fetchColumn('select id from dir_structure where data_id=?', array($dest));
        $strid = self::getDbConnection()->fetchColumn('select id from dir_structure where data_id=?', array($this->id));
		$tree->moveAll($strid, $prntid); 
		
        $this->_url = false;
        $this->_fullUrl = false;
        $this->_treePath = false;
        $this->_path = false;
         
        $this->updateCache();
    }
2807
public static function setDefaultDbo(AbstractDatabaseDriver $db = null)
    {
        self::$db = $db;

        if ($db) {
            $driver = $db->getName();

            self::$instances[$driver] = $db;
        }
    }
761022
protected function query ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		try
		{
			$this->lastaffectedrows = $this->conn->exec($sql);
			if ($this->lastaffectedrows === FALSE) {
				$this->sql_errcheck($sql);
			}
		}
		catch (PDOException $e) 
		{
			$this->sql_errcheck($sql);
		}
	}
153335
public function createDatabase(
        string $dbName,
        string $characterSet = 'utf8mb4',
        string $collate = 'utf8mb4_unicode_ci'
    ): bool {
        $sql = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s;';
        $sql = vsprintf($sql, [
            $this->quoter->quoteName($dbName),
            $this->quoter->quoteValue($characterSet),
            $this->quoter->quoteValue($collate),
        ]);

        return $this->db->exec($sql);
    }
567356
public static function execute($conn, $sql) {
    $conn = is_array($conn) ? self::connect($conn) : $conn;
    $result = $conn->query($sql);
    if (!$result) {
      throw new SqlException("Cannot execute $sql: " . $conn->error);
    }

    if ($result && $result !== TRUE) {
      $result->free_result();
    }

  }
44754
public static function setDbType($dbType) {
        $dbTypeCast = (string) $dbType;
        
        if (array_search($dbTypeCast, self::$dbList) === false) {
            throw new DBException('Illegal database type provided to DB Service');
        }
        
        self::$dbType = $dbTypeCast;
    }
439167
public static function _genSQL ($params = array (), &$db = FALSE)
	{
		
		// Set select

		if (!isset ($params['select']))
		{
			$params['select']	= '*';
		}
		
		// Set from

		if (!isset ($params['from']))
		{
			$params['from']		= '`' . static::$dbTable . '`';
		}
		
		// Get database slave for read

		if ($db === FALSE)
		{
			$db	=& self::_getDbSlave ();
		}
		
		if (!($db instanceof \PDO))
		{
			throw new Exception ('Invalid or no database resource set');
		}
		
		// Return value

		return $db->genSQL ($params);

	}
631714
public function execute($sql, $bind = [], $has_insert_id = false)
    {
        $sql = $this->_replaceQuoteCharacters($sql);

        try {
            $r = $bind ? $this->_execute($sql, $bind)->rowCount() : @$this->_getPdo()->exec($sql);
            if ($has_insert_id) {
                return $this->_getPdo()->lastInsertId();
            } else {
                return $r;
            }
        } catch (\PDOException $e) {
            throw new DbException([
                ':message => ' . PHP_EOL . 'SQL: ":sql"' . PHP_EOL . ' BIND: :bind',
                'message' => $e->getMessage(),
                'sql' => $sql,
                'bind' => json_encode($bind, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
            ]);
        }
    }
1277989
public static function findAllBySql($sql,$data=[],$db_name=''){
		# example: $sql = 'SELECT * FROM  sales_flat_quote';
		$db = self::getDb($db_name);
		$result = $db->createCommand($sql,$data)
					->queryAll();
		return $result;
	}
486802
protected function explainQuery($dbConnection, $query, $parameters = array())
    {
        $driver = $dbConnection->getAttribute(\PDO::ATTR_DRIVER_NAME);
        $query = $this->getExplainQuery($query, $driver);
        $statement = $dbConnection->prepare($query);
        if ($statement === false) {
            throw new Exception('Invalid query passed to explainQuery method');
        }
        $statement->execute($parameters);
        $result = $statement->fetch(\PDO::FETCH_ASSOC);
        if ($result === false) {
            throw new Exception('Query could not be explained with given parameters');
        }
        return $result;
    }
414081
public function checkExistsAndInsertData($data = [], $wheres = [])
    {
        $this->connection();
        $db = DB::table($this->table);
        if (is_array($wheres) && count($wheres) > 0) {
            foreach ($wheres as $field => $value) {
                if (is_array($value)) {
                    $db->whereIn($field, $value);
                } else {
                    $db->where($field, self::OPERATOR_EQUAL_TO, $value);
                }
            }
        } else {
            $db->where($this->primaryKey, self::OPERATOR_EQUAL_TO, $wheres);
        }
        $checkExists = $db->count();
        $this->debug->debug(__FUNCTION__, 'Check Exists Data: ' . $checkExists);
        if (!$checkExists) {
            $id = $db->insertGetId($data);
            $this->debug->debug(__FUNCTION__, 'SQL Queries: ' . $db->toSql());
            $this->debug->debug(__FUNCTION__, 'Result Insert ID: ' . $id);

            return $id;
        } else {
            $this->debug->debug(__FUNCTION__, 'Đã tồn tại bản ghi, bỏ qua không ghi nữa');

            return FALSE;
        }
    }