{"id":168479,"date":"2013-02-06T12:39:03","date_gmt":"2013-02-06T08:39:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=168479"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=168479","title":{"rendered":"<span class=\"post_title\">\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f PDO<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u043b\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0442\u0438\u043f\u0430 INSERT \u0438 UPDATE, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u043e\u0442 \u043d\u0430\u0432\u043e\u0434\u043d\u0438\u0432\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"php\">$paramsArray[\u2018fname\u2019] = $_POST[\u2018fname\u2019]; $paramsArray[\u2018sname\u2019] = $_POST[\u2018sname\u2019]; <\/code><\/pre>\n<p>  \u0412\u0441\u0435\u0445, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u043f\u043e\u0434 \u043a\u0430\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e PDO.<br \/>  \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044f \u0441\u0442\u0430\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c PDO \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e. \u041f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u044d\u043c\u043e\u0446\u0438\u0439 \u0431\u044b\u043b\u0430 \u043c\u0430\u0441\u0441\u0430. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0430\u043c\u043e\u043c\u0443 \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u0441\u044f \u043e \u00ab\u0447\u0438\u0441\u0442\u043a\u0435\u00bb \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432: \u0432\u0441\u0435, \u0447\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u043d\u0430\u043d\u0435\u0441\u0442\u0438 \u0432\u0440\u0435\u0434 \u0431\u0430\u0437\u0435, \u0431\u043b\u0430\u0433\u043e\u043f\u043e\u043b\u0443\u0447\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u0421\u0423\u0411\u0414, \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u043e\u0434\u043d\u043e\u0439 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u041f\u043b\u044e\u0441 \u043a\u043e \u0432\u0441\u0435\u043c\u0443, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0421\u0423\u0411\u0414, \u0447\u0442\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e. \u0412-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c: \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u0438 \u0432\u0441\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u2014 \u0433\u043e\u0442\u043e\u0432\u043e. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u044b\u0435, \u043d\u0430 \u043c\u0430\u043d\u0435\u0440 JDBC, \u0442\u0430\u043a \u0438 \u0438\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"php\">require_once('config.php'); $dbc = new PDO(&quot;mysql:host=&quot;.HOST.&quot;;dbname=&quot;.DATA_BASE_NAME.&quot;;charset=utf8&quot;, USER, PASSWORD);  #\u0414\u043b\u044f \u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u044b\u0445 $sqlString = &quot;INSERT INTO table1(`name`, `text`, `date`) VALUES (?, ?, ?)&quot;; $params = array(&quot;First Post&quot;, &quot;Hello World&quot;, &quot;01\/01\/2013&quot;); $statment = $dbc-&gt;prepare($sqlString); $statment-&gt;execute($params);  #\u0414\u043b\u044f \u0438\u043c\u0435\u043d\u043d\u044b\u0445 $sqlString = &quot;INSERT INTO table1(`name`, `text`, `date`) VALUES (:name, :text, :date)&quot;;  $params = array(&quot;name&quot; =&gt; &quot;Second Post&quot;, &quot;text&quot; =&gt; &quot;Say Hello&quot;, &quot;date&quot; =&gt; &quot;01\/02\/2013&quot;);  $statment = $dbc-&gt;prepare($sqlString); $statment-&gt;execute($params); <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0447\u0435\u0440\u0442\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u0430 \u044d\u0442\u043e \u044f \u0438\u0445 \u0438 \u043f\u043e\u043b\u044e\u0431\u0438\u043b.<\/p>\n<pre><code class=\"php\">$params = array(&quot;text&quot; =&gt; &quot;Habrahabr&quot;, &quot;name&quot; =&gt; &quot;Third Post&quot;, &quot;date&quot; =&gt; &quot;01\/03\/2013&quot;); $statment-&gt;execute($params); <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u0432 \u0435\u0434\u0438\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0435 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"php\">class DB {     static private $dbc         static public function dbc () {         \ttry {         \trequire_once('config.php');             self::$dbc = new PDO(&quot;mysql:host=&quot;.HOST.&quot;;dbname=&quot;.DATA_BASE_NAME.&quot;;charset=utf8&quot;, USER, PASSWORD); \t\t\t} catch(PDOException $exc) { \t\t\t\tLogger::setLog($exc-&gt;getMessage()); \t\t\t\treturn false; \t\t\t} \t\t} \t\tstatic public function insert($sqlString, $object) { \t\t\tif (!isset(self::$dbc)) {                 self::dbc();             }             try{                 $statment = self::$dbc-&gt;prepare($sqlString);                 $statment-&gt;execute((array)$object);                 return self::$dbc-&gt;lastInsertId();             } catch (PDOException $exc) {             \tLogger::setLog($exc-&gt;getMessage());                 return false;             } \t\t} } <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b INSERT. \u0415\u0441\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043e, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0435\u0433\u043e. PDO \u0443\u043c\u0435\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0445 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c. \u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u044b, \u0442\u0430\u043a \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u041b\u0438\u0447\u043d\u043e \u044f \u0447\u0430\u0449\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0432\u0442\u043e\u0440\u044b\u0435.<\/p>\n<p>  \u0417\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0444\u043e\u0440\u043c \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u043c \u043a\u043b\u0430\u0441\u0441 PostController.<\/p>\n<pre><code class=\"php\">class PostController {     const INSERT = &quot;INSERT INTO `posts` (`name`, `text`, `date`) VALUES (:name, :text, :date)&quot;;          public static function post(){         if (isset($_POST[&quot;new_post&quot;])) {             $insertObject = NULL;             $insertObject-&gt;name = $_POST[&quot;name&quot;];             $insertObject-&gt;text = $_POST[&quot;text&quot;];             $insertObject-&gt;date = $_POST[&quot;date&quot;];             DB::insert(self::INSERT, $insertObject);         }     } } <\/code><\/pre>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c, \u0438\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 10 \u2014 20 \u043f\u043e\u043b\u0435\u0439. \u0410 \u0435\u0441\u043b\u0438 \u0438 \u0442\u043e \u0438 \u0434\u0440\u0443\u0433\u043e\u0435? \u0417\u0430\u043f\u0438\u0441\u0438 \u0432\u0438\u0434\u0430 $insertObject-&gt;name = $_POST[\u00abname\u00bb]; \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0445\u043b\u0430\u043c\u043b\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430. \u0415\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e, \u043f\u0435\u0440\u0432\u0430\u044f \u0438\u0434\u0435\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u0430 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443, \u0431\u044b\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435:<\/p>\n<pre><code class=\"php\">DB::insert(self::INSERT, $_POST); <\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u043e\u0440\u043c\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0438\u043c\u0435\u043d\u0430\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 (\u043c\u043e\u0436\u0435\u0442 \u043e\u043d\u043e \u0438 \u043a \u043b\u0443\u0447\u0448\u0435\u043c\u0443?). \u00ab\u041f\u0443\u0441\u0442\u044c PDO \u0441\u0430\u043c \u043d\u0430\u0439\u0434\u0435\u0442 \u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b\u00bb, \u2014 \u0442\u0430\u043a \u044f \u0434\u0443\u043c\u0430\u043b \u0438 \u043e\u0448\u0438\u0431\u0430\u043b\u0441\u044f. \u041a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0438\u0441\u043b\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0438\u043d\u0430\u0447\u0435 PDO \u0432\u044b\u043a\u0438\u043d\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u0430\u043b\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u043d\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">class PostController {     const INSERT = &quot;INSERT INTO `posts` (`name`, `text`, `date`) VALUES (:name, :text, :date)&quot;;          public static function post(){         if (isset($_POST[&quot;new_post&quot;])) {             $insertArray = $_POST;             unset($insertArray[&quot;new_post&quot;]);             DB::insert(self::INSERT, $insertArray);         }     } } <\/code><\/pre>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u043a\u043e\u0434 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0441\u044f, \u0445\u043e\u0442\u044f \u0438 \u0441\u0442\u0430\u043b \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 \u044d\u0442\u043e\u043c \u0433\u043e\u0434\u0443 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u0443\u0440\u0441\u043e\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0442\u0440\u0443\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u0434 \u043e\u0434\u043d\u0438\u043c WEB \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0434\u043b\u044f \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0431\u044b\u043b\u0430 \u043e\u0434\u043d\u0430 \u043e\u0433\u0440\u043e\u043c\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0412 \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0442\u0430\u0431\u043b\u0438\u0446, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0439. \u0412\u044b\u0431\u043e\u0440 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043f\u043e\u043b\u0435\u0439 \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0437\u0430\u0432\u0438\u0441\u0435\u043b \u043e\u0442 \u043c\u0430\u0445\u0438\u043d\u0430\u0446\u0438\u0439 \u043d\u0430 \u0444\u043e\u0440\u043c\u0435. \u0418 \u043f\u0435\u0440\u0432\u044b\u0439, \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u043e\u043b\u0438\u0434\u043d\u044b\u0445 \u043a\u0443\u0441\u043a\u043e\u0432 \u043a\u043e\u0434\u0430, \u0447\u0435\u0433\u043e \u0438\u0437-\u0437\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0441\u0440\u043e\u043a\u043e\u0432 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c. \u0421\u043f\u0443\u0441\u0442\u044f 10 \u043c\u0438\u043d\u0443\u0442 \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u0439 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u043f\u0440\u0438\u0448\u0435\u043b \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 SQL, \u0441\u0430\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u043b \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0438\u0445, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438.<\/p>\n<pre><code class=\"php\">class PostController {     const INSERT = &quot;INSERT INTO `posts` (`name`, `text`, `date`) VALUES (:name, :text, :date)&quot;;      #\u0428\u0430\u0431\u043b\u043e\u043d \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.     #\u0415\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u043c\u043e\u0436\u043d\u043e \u0438\u0445 \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c     const PATTERN = &quot;|:(([-A-Za-z1-9_])*?)|U&quot;; \tpublic static function findObjectInPost($queryString) { \t\t$fields = array(); \t\t$postObject = NULL; \t\tpreg_match_all(self::PATTERN, $queryString, $fields); \t\tforeach ($fields[1] as $value) { \t\t\tif (isset($_POST[$value])) { \t\t\t\t$sender = $_POST[$value]; \t\t\t\tif (strcasecmp($sender, &quot;&quot;) == 0) { \t\t\t\t\t$sender = NULL; \t\t\t\t} \t\t\t\t$postObject-&gt;$value = $sender; \t\t\t} \t\t} \t\treturn $postObject; \t}          public static function post(){         if (isset($_POST[&quot;new_post&quot;])) {             unset($_POST[&quot;new_post&quot;]);             DB::insert(self::INSERT, $_POST);         }     } } <\/code><\/pre>\n<p>  \u0421\u0443\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 findObjectInPost \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c: \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0438\u0449\u0435\u043c \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 $_POST, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0439\u0434\u0435\u043d, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e, \u043a\u0430\u043a \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u044d\u0442\u043e \u043f\u043e\u043b\u0435.<\/p>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u044b\u0441\u0442\u0440\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<pre><code class=\"php\">    public static function post(){         if (isset($_POST[&quot;new_post&quot;])) {             DB::insert(self::INSERT_POST, $insertObject = self::findObjectInPost(self::INSERT_POST));         }             if (isset($_POST[&quot;new_company&quot;])) {             DB::insert(self::INSERT_COMPANY, $insertObject = self::findObjectInPost(self::INSERT_COMPANY));         }            if (isset($_POST[&quot;new_author&quot;])) {             DB::insert(self::INSERT_AUTHOR, $insertObject = self::findObjectInPost(self::INSERT_AUTHOR));         }     } <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u044e\u043c\u0435.<br \/>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0438\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0432 \u043a\u043e\u0434 \u0438 \u0432\u0440\u0435\u043c\u044f, \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e \u043a \u043b\u044e\u0431\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c \u0441 \u0438\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<p>  \u0413\u043b\u0430\u0432\u043d\u044b\u043c \u043c\u0438\u043d\u0443\u0441\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0430\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0445\u043e\u0442\u044f \u044f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0442\u0430\u043a \u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>  \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c. \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435, \u044f \u0434\u0430\u0436\u0435 \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0445\u043e\u0436\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043e\u0434\u043d\u0430\u043a\u043e, \u043e\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u043c\u043d\u0435 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0436\u0435 \u0431\u044b\u043b\u0438 \u043f\u043e\u0442\u0440\u0430\u0447\u0435\u043d\u044b \u043d\u0430 \u0434\u043e\u043b\u0433\u043e\u0436\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043e\u043d. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u043e\u043d\u043e \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u0443 \u0438 \u0432\u0430\u043c. \t\t\t \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/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=\"http:\/\/habrahabr.ru\/post\/168479\/\"> http:\/\/habrahabr.ru\/post\/168479\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u043b\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0442\u0438\u043f\u0430 INSERT \u0438 UPDATE, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u043e\u0442 \u043d\u0430\u0432\u043e\u0434\u043d\u0438\u0432\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"php\">$paramsArray[\u2018fname\u2019] = $_POST[\u2018fname\u2019]; $paramsArray[\u2018sname\u2019] = $_POST[\u2018sname\u2019]; <\/code><\/pre>\n<p>  \u0412\u0441\u0435\u0445, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u043f\u043e\u0434 \u043a\u0430\u0442.  <\/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-168479","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/168479","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=168479"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/168479\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=168479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=168479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=168479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}