{"id":274134,"date":"2016-02-12T09:32:02","date_gmt":"2016-02-12T06:32:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=274134"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=274134","title":{"rendered":"\u0423\u0434\u043e\u0431\u043d\u044b\u0439 php \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 MySQL"},"content":{"rendered":"<p>       \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0434\u0430\u043b\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f php \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 mysql. \u041c\u043e\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u2013 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043c\u0430\u0441\u0441\u0438\u0432, \u0447\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0411\u0414.<\/p>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441:<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"php\">class Db {      private $where;     private $select = '*';     private $limit;     private $order_by;     private $query;     private $set;      private function query_string($table){         $query = ($this-&gt;query) ? $this-&gt;query : &quot;SELECT $this-&gt;select FROM $table WHERE $this-&gt;where $this-&gt;order_by $this-&gt;limit&quot;;         return $query;     }     function query($text){         $this-&gt;query = $text;         return $this;     }     function where_text($text){         $operator = 'AND';         if (!$this-&gt;where){             $this-&gt;where = $text;         } else {             $this-&gt;where .= $operator.&quot; &quot;.$text;         }         return $this;     }     function order_by_text($text){         if (!$this-&gt;order_by){             $this-&gt;order_by = ' ORDER BY '.$text;         } else {             $this-&gt;order_by .= ', '.$text;         }     }     function connect($host,$login_mysql,$password_mysql,$baza_name) {         $db = @mysql_connect(&quot;$host&quot;, &quot;$login_mysql&quot;, &quot;$password_mysql&quot;);         mysql_set_charset('utf8',$db);         if (!$db) exit(&quot;&lt;p&gt;Sorry, not available MySQL server&lt;\/p&gt;&quot;);         if (!@mysql_select_db($baza_name,$db)) exit(&quot;&lt;p&gt;Unfortunately, the database is not available&lt;\/p&gt;&quot;);     }     function select($column){         $this-&gt;select = $column;         return $this;     }     function limit($start,$count){         $this-&gt;limit = ' LIMIT '.$start.','.$count;         return $this;     }     function order_by($key){         if (is_array($key)){             foreach ($key as $column =&gt; $value){                 if (!$this-&gt;order_by){                     $this-&gt;order_by = ' ORDER BY '.$column.' '.$value;                 } else {                     $this-&gt;order_by .= ', '.$column.' '.$value;                 }             }         } else {             if (!$this-&gt;order_by){                 $this-&gt;order_by = ' ORDER BY '.$key;             } else {                 $this-&gt;order_by .= ', '.$key;             }         }         return $this;     }     function where($key,$compare = '='){         $operator = 'AND';         if (is_array($key)){             foreach ($key as $column=&gt;$value){                 if (!$this-&gt;where){                     $this-&gt;where = $column.$compare.&quot;'&quot;.$value.&quot;' &quot;;                 } else {                     $this-&gt;where .= $operator.&quot; &quot;.$column.$compare.&quot;'&quot;.$value.&quot;' &quot;;                 }             }         } else {             $key = explode(',',$key);             if (!$this-&gt;where){                 $this-&gt;where = $key[0].$compare.&quot;'&quot;.$key[1].&quot;' &quot;;             } else {                 $this-&gt;where .= $operator.&quot; &quot;.$key[0].$compare.&quot;'&quot;.$key[1].&quot;' &quot;;             }         }         return $this;     }     function search($column,$search){         $operator = 'AND';         $search = strtr($search,array(&quot; &quot;=&gt;&quot; +&quot;));         $search = '+'.$search;         $w = 'MATCH('.$column.&quot;) AGAINST('&quot;.$search.&quot;' IN BOOLEAN MODE)&quot;;         if (!$this-&gt;where){             $this-&gt;where = $w;         } else {             $this-&gt;where .= $operator.&quot; &quot;.$w;         }         return $this;     }     function lines($table,$ext = true){         $msql_query = mysql_query($this-&gt;query_string($table));         $line = mysql_fetch_assoc($msql_query);         if ($ext)$this-&gt;exit_function();         return $line;     }     function multiline($table,$ext = true){         $msql_query = mysql_query($this-&gt;query_string($table));         $multiline = array();         while($arr = mysql_fetch_assoc($msql_query)) $multiline[] = $arr;         if ($ext)$this-&gt;exit_function();         return $multiline;     }     function num_rows($table,$ext = true){         $msql_query = mysql_query($this-&gt;query_string($table));         $num_rows = mysql_num_rows($msql_query);         if ($ext)$this-&gt;exit_function();         return $num_rows;     }     function insert($table){         $query = 'INSERT '.$table.$this-&gt;set;         $q = mysql_query($query);         $this-&gt;exit_function();         return  $q ? mysql_insert_id() : 'ERROR INSERT MYSQL';     }     function update($table){         $query = 'UPDATE '.$table.$this-&gt;set.' WHERE '.$this-&gt;where;         $this-&gt;exit_function();         return mysql_query($query);     }     function set($value){         $operator = ',';         if (is_array($value)){             foreach ($value as $column=&gt;$val){                 if (!$this-&gt;set){                     $this-&gt;set = ' SET '.$column.'='.&quot;'&quot;.$val.&quot;' &quot;;                 } else {                     $this-&gt;set .= $operator.&quot; &quot;.$column.'='.&quot;'&quot;.$val.&quot;' &quot;;                 }             }         } else {             $value = explode(',',$value);             if (!$this-&gt;set){                 $this-&gt;set = ' SET '.$value[0].'='.&quot;'&quot;.$value[1].&quot;' &quot;;             } else {                 $this-&gt;where .= $operator.&quot; &quot;.$value[0].'='.&quot;'&quot;.$value[1].&quot;' &quot;;             }         }         return $this;     }     private function exit_function(){         $this-&gt;where = '';         $this-&gt;select = '*';         $this-&gt;limit = '';         $this-&gt;order_by = '';         $this-&gt;query = '';         return $this;     } }  <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0411\u0414) \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Db \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 connect \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0411\u0414. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438: connect(\u0425\u043e\u0441\u0442, \u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0430\u0440\u043e\u043b\u044c, \u0438\u043c\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445);<\/p>\n<pre><code class=\"php\">$db = new Db; $db-&gt;connect('localhost','root','',test); <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u0440\u0430\u0431\u043e\u0442\u0435. \u0414\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e \u043c\u0430\u0441\u0441\u0438\u0432, \u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e where, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u043c\u0430\u0441\u0441\u0438\u0432:<\/p>\n<pre><code class=\"php\">$where = array(); $where['status'] = 1; $where['category'] = 2; $db-&gt;where($where); <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e where \u043e\u043f\u0438\u0448\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. \u0410 \u0441\u0435\u0439\u0447\u0430\u0441 \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u0438\u0437 \u043a\u0430\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0456\u044e select, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 * \u0438 \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c.<\/p>\n<pre><code class=\"php\">$db-&gt;select('msg,zag'); <\/code><\/pre>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e where \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0437\u043d\u0430\u043a = \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0442\u043e\u0440\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0437\u043d\u0430\u043a \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f. \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#8216;price,1000&#8217;, \u0442\u0430\u043a \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u0438 \u0432\u0441\u0435\u043c\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0437\u043d\u0430\u043a.<\/p>\n<pre><code class=\"php\">$db-&gt;where('price,1000','&gt;'); <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e order_by, \u0434\u043b\u044f \u043d\u0435\u0435 \u0442\u0430\u043a\u0436\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432:<\/p>\n<pre><code class=\"php\">$order_by = array(); $order_by['price'] = 'DESC'; $order_by['data'] = 'ASC'; $db-&gt;order_by($order_by); <\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441: ORDER BY price DESC, data ASC. \u0412 ORDER BY \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e order_by_text():<\/p>\n<pre><code class=\"php\">$db-&gt;order_by_text('id DESC'); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0438\u0445 \u0442\u0440\u0438: num_rows, multiline, lines:<\/p>\n<pre><code class=\"php\">$q['num'] = $db-&gt;num_rows('data',false); <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f num_rows \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0443, false \u2014 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0442\u0438\u0440\u0430\u0442\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e. \u0411\u0435\u0437 false \u0432\u0441\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0438 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e. \u2018data\u2019 \u2013 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432 \u0411\u0414 \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<pre><code class=\"php\">$q['multiline'] = $db-&gt;multiline('data',false); <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f multiline \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0443.<\/p>\n<pre><code class=\"php\">$q['lines'] = $db-&gt;lines('data'); <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f lines \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u0434\u0438\u043d \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u0443.<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441: <br \/>  SELECT msg,zag FROM data WHERE status=&#8217;1&#8242; AND category=&#8217;2&#8242; AND price&gt;&#8217;1000&#8242; ORDER BY price DESC, data ASC, id DESC<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f limit \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 LIMIT \u0432 \u0437\u0430\u043f\u0440\u043e\u0441, \u0433\u0434\u0435 2 \u2014 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 (\u0442.\u0435. \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u0447\u043d\u0435\u0442\u0441\u044f \u0441\u043e 2-\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443), 4 \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435.<\/p>\n<pre><code class=\"php\">$q['multiline'] = $db-&gt;select('id')-&gt;where($where)-&gt;where_text('id IN (1,2,3,4)')-&gt;order_by($order_by)-&gt;limit(2,4)-&gt;multiline('data'); <\/code><\/pre>\n<p>  Select, where \u0438 order_by \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043d\u043e\u0432\u043e, \u0442.\u043a. \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f lines \u0431\u044b\u043b\u0430 \u0431\u0435\u0437 false \u2014 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0431\u044b\u043b\u0438 \u0441\u0442\u0435\u0440\u0442\u044b. \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  SELECT id FROM data WHERE status=&#8217;1&#8242; AND category=&#8217;2&#8242; AND id IN (1,2,3,4) ORDER BY price DESC, data ASC LIMIT 2,4<\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0431\u044b\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f where_text \u2013 \u043e\u043d\u0430 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0430\u043c\u043e\u043c\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 WHERE<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f search:<\/p>\n<pre><code class=\"php\">$q['search'] = $db-&gt;search('test,text','\u0442\u0435\u0441\u0442 \u043f\u043e\u0438\u0441\u043a\u0430')-&gt;multiline('data'); <\/code><\/pre>\n<p>  \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441: SELECT * FROM data WHERE MATCH(test,text) AGAINST(&#8216;+\u0442\u0435\u0441\u0442 +\u043f\u043e\u0438\u0441\u043a\u0430&#8217; IN BOOLEAN MODE). \u0418\u0449\u0435\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 data, \u0432 \u043f\u043e\u043b\u044f\u0445 test \u0438 text \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0442\u0435\u0441\u0442 \u0438 \u043f\u043e\u0438\u0441\u043a\u0430.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">$db-&gt;select('id')-&gt;where($where)-&gt;search('test,text','\u0442\u0435\u0441\u0442 \u043f\u043e\u0438\u0441\u043a\u0430')-&gt;order_by($order_by)-&gt;multiline('data'); <\/code><\/pre>\n<p>  $order_by \u0438 $where \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  SELECT id FROM data WHERE status=&#8217;1&#8242; AND category=&#8217;2&#8242; AND MATCH(test,text) AGAINST(&#8216;+\u0442\u0435\u0441\u0442 +\u043f\u043e\u0438\u0441\u043a\u0430&#8217; IN BOOLEAN MODE) ORDER BY price DESC, data ASC<\/p>\n<p>  \u0414\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e set \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0438 insert \u2014 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"php\">$set['test'] = 'test'; $set['text'] = 'text'; $id = $db-&gt;set($set)-&gt;insert('data');  <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 id \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e $id. \u0417\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a: INSERT data SET test=&#8217;test&#8217;, text=&#8217;text&#8217;<\/p>\n<p>  \u0414\u043b\u044f \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e update:<\/p>\n<pre><code class=\"php\">$set = array(); $set['category'] = 2; $set['test'] = 'test change'; $set['text'] = 'text change'; $save = $db-&gt;where('id,1')-&gt;set($set)-&gt;update('data'); $message = $save ? &quot;UPDATE OK&quot; : &quot;ERROR UPDATE&quot;;  <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, $message \u0432\u0435\u0440\u043d\u0435\u0442 UPDATE OK \u0438\u043d\u0430\u0447\u0435 ERROR UPDATE. \u0417\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c: <\/p>\n<p>  UPDATE data SET test=&#8217;test&#8217;, text=&#8217;text&#8217;, category=&#8217;2&#8242;, test=&#8217;test change&#8217;, text=&#8217;text change&#8217; WHERE id=&#8217;1&#8242;<\/p>\n<p>  \u0418 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f query \u2014 \u0432 \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 select \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e:<\/p>\n<pre><code class=\"php\">$q = $db-&gt;query(&quot;SELECT * FROM data WHERE status='1' AND category='2'&quot;)-&gt;multiline('data'); <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"php\">$db2 = new Db(); $db2-&gt;connect('localhost','root','','test'); $q['db2'] = $db2-&gt;where('id,2')-&gt;lines('wp_posts'); print &quot;&lt;pre&gt;&quot;; print_r ($q); <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f. \u041d\u0435 \u0431\u0443\u0434\u0443 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043a\u043b\u0430\u0441c\u0430\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414, \u0437\u043d\u0430\u044e \u2014 \u0438\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u041f\u0443\u0431\u043b\u0438\u043a\u0443\u044e \u0435\u0433\u043e, \u0442.\u043a. \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e, \u043c\u043e\u0436\u0435\u0442, \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u0440\u0438\u0442\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0443\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434.       <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/277095\/\"> https:\/\/habrahabr.ru\/post\/277095\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0434\u0430\u043b\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f php \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 mysql. \u041c\u043e\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u2013 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043c\u0430\u0441\u0441\u0438\u0432, \u0447\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0411\u0414.<\/p>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441:  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-274134","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/274134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=274134"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/274134\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=274134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=274134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=274134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}