diff --git a/src/ZM/MySQL/MySQLWrapper.php b/src/ZM/MySQL/MySQLWrapper.php index 23aa720b..61074261 100644 --- a/src/ZM/MySQL/MySQLWrapper.php +++ b/src/ZM/MySQL/MySQLWrapper.php @@ -13,6 +13,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Types\Type; use Throwable; use Traversable; use ZM\Exception\DbException; @@ -113,10 +114,10 @@ class MySQLWrapper } /** - * @param mixed $table + * @param string $table 表 * @throws DbException */ - public function delete($table, array $criteria, array $types = []): int + public function delete(string $table, array $criteria, array $types = []): int { try { return $this->connection->delete($table, $criteria, $types); @@ -127,9 +128,9 @@ class MySQLWrapper /** * wrapper method - * @param mixed $level + * @param int $level Sets the transaction isolation level */ - public function setTransactionIsolation($level): int + public function setTransactionIsolation(int $level): int { return $this->connection->setTransactionIsolation($level); } @@ -144,10 +145,10 @@ class MySQLWrapper /** * wrapper method - * @param mixed $table + * @param string $table 表名 * @throws DbException */ - public function update($table, array $data, array $criteria, array $types = []): int + public function update(string $table, array $data, array $criteria, array $types = []): int { try { return $this->connection->update($table, $data, $criteria, $types); @@ -158,10 +159,10 @@ class MySQLWrapper /** * wrapper method - * @param mixed $table + * @param string $table 表名 * @throws DbException */ - public function insert($table, array $data, array $types = []): int + public function insert(string $table, array $data, array $types = []): int { try { return $this->connection->insert($table, $data, $types); @@ -172,18 +173,17 @@ class MySQLWrapper /** * wrapper method - * @param mixed $str + * @param string $str The name to be quoted */ - public function quoteIdentifier($str): string + public function quoteIdentifier(string $str): string { return $this->connection->quoteIdentifier($str); } /** * wrapper method - * @param mixed $value - * @param int $type - * @return mixed + * @param mixed $value + * @param null|int|string|Type $type */ public function quote($value, $type = ParameterType::STRING) { @@ -192,7 +192,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return array> */ public function fetchAllNumeric(string $query, array $params = [], array $types = []): array { @@ -205,7 +210,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return array> */ public function fetchAllAssociative(string $query, array $params = [], array $types = []): array { @@ -218,6 +228,10 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException */ public function fetchAllKeyValue(string $query, array $params = [], array $types = []): array @@ -231,7 +245,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return array> */ public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []): array { @@ -244,7 +263,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return array */ public function fetchFirstColumn(string $query, array $params = [], array $types = []): array { @@ -257,7 +281,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return Traversable> */ public function iterateNumeric(string $query, array $params = [], array $types = []): Traversable { @@ -270,7 +299,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return Traversable> */ public function iterateAssociative(string $query, array $params = [], array $types = []): Traversable { @@ -283,7 +317,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return Traversable */ public function iterateKeyValue(string $query, array $params = [], array $types = []): Traversable { @@ -296,7 +335,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return Traversable> */ public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []): Traversable { @@ -309,7 +353,12 @@ class MySQLWrapper /** * wrapper method + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return Traversable */ public function iterateColumn(string $query, array $params = [], array $types = []): Traversable { @@ -322,11 +371,13 @@ class MySQLWrapper /** * wrapper method - * @param mixed $sql - * @param array $types + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * * @throws DbException */ - public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheProfile $qcp = null): MySQLStatementWrapper + public function executeQuery(string $sql, array $params = [], array $types = [], ?QueryCacheProfile $qcp = null): MySQLStatementWrapper { try { $query = $this->connection->executeQuery($sql, $params, $types, $qcp); @@ -338,12 +389,12 @@ class MySQLWrapper /** * wrapper method - * @param mixed $sql - * @param mixed $params - * @param mixed $types + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * @throws DbException */ - public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp): MySQLStatementWrapper + public function executeCacheQuery(string $sql, array $params, array $types, QueryCacheProfile $qcp): MySQLStatementWrapper { try { $query = $this->connection->executeCacheQuery($sql, $params, $types, $qcp); @@ -355,10 +406,14 @@ class MySQLWrapper /** * wrapper method - * @param mixed $sql + * @param string $sql SQL statement + * @param array|array $params Statement parameters + * @param array|array $types Parameter types + * * @throws DbException + * @return int|string the number of affected rows */ - public function executeStatement($sql, array $params = [], array $types = []): int + public function executeStatement(string $sql, array $params = [], array $types = []) { try { return $this->connection->executeStatement($sql, $params, $types); @@ -377,9 +432,10 @@ class MySQLWrapper /** * wrapper method - * @param null $name + * @param null|string $name name of the sequence object from which the ID should be returned + * @return false|int|string a string representation of the last inserted ID */ - public function lastInsertId($name = null): string + public function lastInsertId(?string $name = null) { return $this->connection->lastInsertId($name); } @@ -404,13 +460,12 @@ class MySQLWrapper /** * wrapper method - * @param mixed $nestTransactionsWithSavepoints * @throws DbException */ - public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) + public function setNestTransactionsWithSavepoints(bool $nest_transactions_with_savepoints) { try { - $this->connection->setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints); + $this->connection->setNestTransactionsWithSavepoints($nest_transactions_with_savepoints); } catch (Throwable $e) { throw new DbException($e->getMessage(), $e->getCode(), $e); } @@ -460,10 +515,10 @@ class MySQLWrapper /** * wrapper method - * @param mixed $savepoint + * @param string $savepoint the name of the savepoint to create * @throws DbException */ - public function createSavepoint($savepoint) + public function createSavepoint(string $savepoint) { try { $this->connection->createSavepoint($savepoint); @@ -474,10 +529,10 @@ class MySQLWrapper /** * wrapper method - * @param mixed $savepoint + * @param string $savepoint the name of the savepoint to release * @throws DbException */ - public function releaseSavepoint($savepoint) + public function releaseSavepoint(string $savepoint) { try { $this->connection->releaseSavepoint($savepoint); @@ -488,10 +543,10 @@ class MySQLWrapper /** * wrapper method - * @param mixed $savepoint + * @param string $savepoint the name of the savepoint to rollback to * @throws DbException */ - public function rollbackSavepoint($savepoint) + public function rollbackSavepoint(string $savepoint) { try { $this->connection->rollbackSavepoint($savepoint);