@@ -86,7 +86,8 @@ public function setModel($modelClass) {
8686
8787 /**
8888 * SQL 语句预处理并执行
89- * @param string $sqlStatement, array $parameters
89+ * @param string $sqlStatement
90+ * @param array $parameters
9091 * @return boolean
9192 * @uses 用于预处理并执行语句,请注意本方法结合了 pdo 中 prepare 和 execute 两个方法
9293 */
@@ -194,9 +195,9 @@ public function where($sqlConditionArray = []){
194195 // 传入条件,进行 SQL 语句拼接
195196 foreach ($ sqlConditionArray as $ key => $ value ) {
196197 if (isset ($ whereSQL )) {
197- $ whereSQL .= " AND " .$ key .'=" ' .$ value .'" ' ;
198+ $ whereSQL .= " AND " .$ key .'=" ' .addslashes ( $ value) .'" ' ;
198199 } else {
199- $ whereSQL = $ key .'=" ' .$ value .'" ' ;
200+ $ whereSQL = $ key .'=" ' .addslashes ( $ value) .'" ' ;
200201 }
201202 }
202203 $ this ->where = '( ' .$ whereSQL .') ' ;
@@ -212,9 +213,9 @@ public function where($sqlConditionArray = []){
212213 // 传入条件,进行 SQL 语句拼接
213214 foreach ($ sqlConditionArray as $ key => $ value ) {
214215 if (isset ($ whereSQL )) {
215- $ whereSQL .= " AND " .$ key .'=" ' .$ value .'" ' ;
216+ $ whereSQL .= " AND " .$ key .'=" ' .addslashes ( $ value) .'" ' ;
216217 } else {
217- $ whereSQL = $ key .'=" ' .$ value .'" ' ;
218+ $ whereSQL = $ key .'=" ' .addslashes ( $ value) .'" ' ;
218219 }
219220 }
220221 $ this ->where .= ' AND ( ' .$ whereSQL .') ' ;
@@ -274,9 +275,9 @@ public function orWhere($sqlConditionArray = []){
274275 // 传入条件,进行 SQL 语句拼接
275276 foreach ($ sqlConditionArray as $ key => $ value ) {
276277 if (isset ($ whereSQL )) {
277- $ whereSQL .= " AND " .$ key .'=" ' .$ value .'" ' ;
278+ $ whereSQL .= " AND " .$ key .'=" ' .addslashes ( $ value) .'" ' ;
278279 } else {
279- $ whereSQL = $ key .'=" ' .$ value .'" ' ;
280+ $ whereSQL = $ key .'=" ' .addslashes ( $ value) .'" ' ;
280281 }
281282 }
282283 $ this ->where .= ' OR ( ' .$ whereSQL .') ' ;
@@ -306,7 +307,8 @@ public function orWhereRaw($sqlConditionStatement = ''){
306307
307308 /**
308309 * join 语句
309- * @param string $table, string $method = inner
310+ * @param string $table, string
311+ * @param$method = inner
310312 * @return Database
311313 * @uses 用于根据两个或多个表中的列之间的关系查询数据。其中 method 可选 left, right, full, inner
312314 */
@@ -340,7 +342,8 @@ public function on($sqlConditionStatement){
340342
341343 /**
342344 * 根据字段排列结果集
343- * @param string|array $field, string $method
345+ * @param string|array $field
346+ * @param string $method
344347 * @return Database
345348 * @uses 根据字段排列结果集, 其中 $field 可为单个字段字符串或关联数组
346349 */
@@ -422,9 +425,15 @@ public function delete(){
422425 return $ this ->prepare ($ this ->SQLStatement );
423426 }
424427
428+ public function count (){
429+ $ countSQL = str_replace ($ select , 'COUNT( ' .$ select .') ' , $ this ->SQLStatement );
430+ return $ this ->PDOConnect ->query ($ countSQL )->fetch ()[0 ];
431+ }
432+
425433 /**
426434 * Database 分页
427- * @param int $pageNum, boolean $furtherPageInfo
435+ * @param int $pageNum
436+ * @param boolean $furtherPageInfo
428437 * @return Collection
429438 * @uses 数据库 LIMIT 语句调用
430439 */
0 commit comments