"年初的承诺,但愿此次能写完dAY10 ------- Sidney"php
刚才发了一博客java
里面有一段是这么写的mysql
/** * Read records from database by specified fields and values * When 1st parameter is an array, it's expected to be an associative array of field => value pairs to read data by * When 2nd parameter is a scalar, it's expected to be a field name and second parameter - it's value * * @param string|array[optional] $field * @param mixed[optional] $value * @param string[optional] $orderBy Ordering rule * @param int[optional] $page Paging paramter used to limit number of records returned * @param int[optional] $perPage Page size when paging parameter is used (20 by default) * @return PMXI_Model_List */ public function getBy($field = NULL, $value = NULL, $orderBy = NULL, $page = NULL, $perPage = NULL, $groupBy = NULL) { if (is_array($field) or is_null($field)) { // when associative array is submitted, do not expect second paramter to be $value, but act as if there is no $value parameter at all $groupBy = $perPage; $perPage = $page; $page = $orderBy; $orderBy = $value; $value = NULL; } ! is_null($perPage) or $perPage = 20; // set default value for page length $page = intval($page); $sql = "FROM $this->table "; $sql .= implode(' ', $this->joined); if ( ! is_null($field)) { $sql .= " WHERE " . $this->buildWhere($field, $value); } if ( ! is_null($groupBy)) { $sql .= " GROUP BY $groupBy"; } is_null($orderBy) and $orderBy = implode(', ', $this->primary); // default sort order is by primary key $sql .= " ORDER BY $orderBy"; if ($page > 0) { $sql = "SELECT SQL_CALC_FOUND_ROWS $this->what $sql LIMIT " . intval(($page - 1) * $perPage) . ", " . intval($perPage); } else { $sql = "SELECT $this->what $sql"; } $result = $this->wpdb->get_results($sql, ARRAY_A);
刚才博客也说了,这是一个10w行代码里面找出来的一个小片断算法
(这10万行代码还只是为了实现一个csv上传的功能)sql
这个小片断来源于一个大mvc框架(非wordpress框架)里面的model层的一个查询数据库的实现数据库
整个片断代码也只有最后一句话有用:缓存
“$result = $this->wpdb->get_results($sql, ARRAY_A);”mvc
也就是这句话应该完全解决了全部人的迷思:oracle
“”不管再大的框架,最终仍是拼装spl,作数据库查询,经过wordpress的db,wpdb作查询,只是人家作得比较优雅而已“”app
public function query($query) { //... $query = apply_filters( 'query', $query ); //...重要的原来在后面 }
public function query($query){ //... $query = apply_filters('query',$query); //... if ( ! empty( $this->dbh ) && $this->use_mysqli ) { $this->result = mysqli_query( $this->dbh, $query ); } elseif ( ! empty( $this->dbh ) ) { $this->result = mysql_query( $query, $this->dbh ); } }(记得之前好像还能够支持oracle和mysql,如今明显就是mysql比较好)