クラス wpdb::query()
クラス wpdb::query()
定義ファイル :/blog/wp-includes/wp-db.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | public function query( $query ) { if ( ! $this->ready ) return false; $query = apply_filters( 'query', $query ); $this->flush(); $this->func_call = "\$db->query(\"$query\")"; $this->last_query = $query; $this->_do_query( $query ); $mysql_errno = 0; if ( ! empty( $this->dbh ) ) { if ( $this->use_mysqli ) { $mysql_errno = mysqli_errno( $this->dbh ); } else { $mysql_errno = mysql_errno( $this->dbh ); } } if ( empty( $this->dbh ) || 2006 == $mysql_errno ) { if ( $this->check_connection() ) { $this->_do_query( $query ); } else { $this->insert_id = 0; return false; } } if ( $this->use_mysqli ) { $this->last_error = mysqli_error( $this->dbh ); } else { $this->last_error = mysql_error( $this->dbh ); } if ( $this->last_error ) { if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) $this->insert_id = 0; $this->print_error(); return false; } if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { $return_val = $this->result; } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { if ( $this->use_mysqli ) { $this->rows_affected = mysqli_affected_rows( $this->dbh ); } else { $this->rows_affected = mysql_affected_rows( $this->dbh ); } if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { if ( $this->use_mysqli ) { $this->insert_id = mysqli_insert_id( $this->dbh ); } else { $this->insert_id = mysql_insert_id( $this->dbh ); } } $return_val = $this->rows_affected; } else { $num_rows = 0; if ( $this->use_mysqli ) { while ( $row = @mysqli_fetch_object( $this->result ) ) { $this->last_result[$num_rows] = $row; $num_rows++; } } else { while ( $row = @mysql_fetch_object( $this->result ) ) { $this->last_result[$num_rows] = $row; $num_rows++; } } $this->num_rows = $num_rows; $return_val = $num_rows; } return $return_val; } |