From 6d9fa4783864be373a018f345f4525a571bcf174 Mon Sep 17 00:00:00 2001 From: skjan Date: Tue, 1 Dec 2020 11:01:24 +0800 Subject: [PATCH] feat: add unbuffered mode, insert tablename remove `` --- src/PDO.class.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/PDO.class.php b/src/PDO.class.php index 48d46dd..a7b757b 100644 --- a/src/PDO.class.php +++ b/src/PDO.class.php @@ -114,7 +114,7 @@ private function SetFailureFlag() public function closeConnection() { $this->pdo = null; - } + } private function Init($query, $parameters = null, $driverOptions = array()) { @@ -211,6 +211,17 @@ public function inTransaction() return $this->pdo->inTransaction(); } + /** + * mysql unbuffered mode, suitable for reading huge data source + * @see https://www.php.net/manual/en/mysqlinfo.concepts.buffering.php + * + * @return void + */ + public function unbuffered() + { + $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); + } + /** * execute a sql query, returns an result array in the select operation, and returns the number of rows affected in other operations * @param string $query @@ -264,7 +275,7 @@ public function insert($tableName, $params = null) { $keys = array_keys($params); $rowCount = $this->query( - 'INSERT INTO `' . $tableName . '` (`' . implode('`,`', $keys) . '`) + 'INSERT INTO ' . $tableName . ' (`' . implode('`,`', $keys) . '`) VALUES (:' . implode(',:', $keys) . ')', $params ); @@ -349,7 +360,6 @@ public function lastInsertId() return $this->pdo->lastInsertId(); } - /** * @param $query * @param null $params