{"id":135338,"date":"2026-07-22T12:28:07","date_gmt":"2026-07-22T06:28:07","guid":{"rendered":"https:\/\/rcl-radio.ru\/?p=135338"},"modified":"2026-07-22T12:28:07","modified_gmt":"2026-07-22T06:28:07","slug":"%d0%be%d0%b1%d0%bd%d0%be%d0%b2%d0%bb%d1%8f%d0%b5%d0%bc-%d0%b8-%d1%83%d0%b4%d0%b0%d0%bb%d1%8f%d0%b5%d0%bc-%d0%b2-mysql-%d0%b8%d0%b7-php-update-%d0%b8-delete-%d1%81-%d0%bf%d1%80%d0%be%d0%b2%d0%b5%d1%80","status":"publish","type":"post","link":"https:\/\/rcl-radio.ru\/?p=135338","title":{"rendered":"\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432 MySQL \u0438\u0437 PHP: UPDATE \u0438 DELETE \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439"},"content":{"rendered":"<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f (<code class=\"CodeInlined\">UPDATE<\/code>) \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f (<code class=\"CodeInlined\">DELETE<\/code>) \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MySQL \u0447\u0435\u0440\u0435\u0437 PHP \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c PDO. \u041e\u0441\u043e\u0431\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0443\u0434\u0435\u043b\u0435\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430\u043c: \u043d\u0430\u043b\u0438\u0447\u0438\u044e \u0437\u0430\u043f\u0438\u0441\u0438, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0438 \u0437\u0430\u0449\u0438\u0442\u0435 \u043e\u0442 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<hr \/>\n<h2>\u0412\u0430\u0436\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e: \u0431\u0435\u0437 <code class=\"CodeInlined\">WHERE<\/code> \u2014 \u043d\u0435\u043b\u044c\u0437\u044f<\/h2>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 <code class=\"CodeInlined\">UPDATE<\/code> \u0438 <code class=\"CodeInlined\">DELETE<\/code> \u0431\u0435\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u044f <code class=\"CodeInlined\">WHERE<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a\u043e \u0432\u0441\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u041e\u0434\u043d\u0430 \u043e\u043f\u0435\u0447\u0430\u0442\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0435\u0440\u0435\u0442\u044c \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u043e\u0434\u0435 \u0432\u0441\u0435\u0433\u0434\u0430:<\/p>\n<ol>\n<li data-value=\"1.\" data-shift=\"1\">\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c.<\/li>\n<li data-value=\"2.\" data-shift=\"1\">\u0417\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441 \u0442\u043e\u0447\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c.<\/li>\n<li data-value=\"3.\" data-shift=\"1\">\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 (<code class=\"CodeInlined\">rowCount()<\/code>).<\/li>\n<li data-value=\"4.\" data-shift=\"1\">\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 <code class=\"CodeInlined\">try\/catch<\/code>.<\/li>\n<\/ol>\n<hr \/>\n<h2>UPDATE: \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430<\/h2>\n<h3>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439<\/h3>\n<p>\u041d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c email \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e \u0435\u0433\u043e <code class=\"CodeInlined\">id<\/code>. \u041f\u0435\u0440\u0435\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0430 \u043f\u043e\u0441\u043b\u0435\u00a0\u2014\u00a0\u0447\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0430\u0441\u044c \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430.<\/p>\n<h3>SQL<\/h3>\n<pre class=\"sql\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #993333; font-weight: bold;\">SELECT<\/span> id <span style=\"color: #993333; font-weight: bold;\">FROM<\/span> users <span style=\"color: #993333; font-weight: bold;\">WHERE<\/span> id <span style=\"color: #66cc66;\">=<\/span> :id;\r\n\u00a0\r\n<span style=\"color: #993333; font-weight: bold;\">UPDATE<\/span> users <span style=\"color: #993333; font-weight: bold;\">SET<\/span> email <span style=\"color: #66cc66;\">=<\/span> :email <span style=\"color: #993333; font-weight: bold;\">WHERE<\/span> id <span style=\"color: #66cc66;\">=<\/span> :id;<\/pre>\n<h3>PHP-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<pre class=\"sql\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #66cc66;\">&lt;<\/span>?php\r\n$dsn <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff0000;\">'mysql:host=localhost;dbname=test_db;charset=utf8mb4'<\/span>;\r\n$user <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff0000;\">'db_user'<\/span>;\r\n$pass <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff0000;\">'db_pass'<\/span>;\r\n\u00a0\r\ntry <span style=\"color: #66cc66;\">{<\/span>\r\n    $pdo <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> PDO<span style=\"color: #66cc66;\">(<\/span>$dsn<span style=\"color: #66cc66;\">,<\/span> $user<span style=\"color: #66cc66;\">,<\/span> $pass<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #66cc66;\">[<\/span>\r\n        PDO::ATTR_ERRMODE            <span style=\"color: #66cc66;\">=&gt;<\/span> PDO::ERRMODE_EXCEPTION<span style=\"color: #66cc66;\">,<\/span>\r\n        PDO::ATTR_DEFAULT_FETCH_MODE <span style=\"color: #66cc66;\">=&gt;<\/span> PDO::FETCH_ASSOC<span style=\"color: #66cc66;\">,<\/span>\r\n    <span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    $id   <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #cc66cc;\">123<\/span>;\r\n    $email <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff0000;\">'new.email@example.com'<\/span>;\r\n\u00a0\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0428\u0430\u0433 <span style=\"color: #cc66cc;\">1<\/span>: \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f\r\n    $stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'SELECT id FROM users WHERE id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">':id'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $row <span style=\"color: #66cc66;\">=<\/span> $stmt<span style=\"color: #66cc66;\">-&gt;<\/span>fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    <span style=\"color: #993333; font-weight: bold;\">IF<\/span> <span style=\"color: #66cc66;\">(<\/span>!$row<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n        throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> Exception<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0428\u0430\u0433 <span style=\"color: #cc66cc;\">2<\/span>: \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <span style=\"color: #993333; font-weight: bold;\">UPDATE<\/span>\r\n    $stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'UPDATE users SET email = :email WHERE id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span>\r\n        <span style=\"color: #ff0000;\">':email'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $email<span style=\"color: #66cc66;\">,<\/span>\r\n        <span style=\"color: #ff0000;\">':id'<\/span>    <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">,<\/span>\r\n    <span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0428\u0430\u0433 <span style=\"color: #cc66cc;\">3<\/span>: \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\r\n    $affected <span style=\"color: #66cc66;\">=<\/span> $stmt<span style=\"color: #66cc66;\">-&gt;<\/span>rowCount<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #993333; font-weight: bold;\">IF<\/span> <span style=\"color: #66cc66;\">(<\/span>$affected !<span style=\"color: #66cc66;\">==<\/span> <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n        throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> Exception<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c: \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u043e \u0441\u0442\u0440\u043e\u043a: '<\/span> <span style=\"color: #66cc66;\">.<\/span> $affected<span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n    echo <span style=\"color: #ff0000;\">'\u0417\u0430\u043f\u0438\u0441\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0430.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span> catch <span style=\"color: #66cc66;\">(<\/span>Exception $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 $e<span style=\"color: #66cc66;\">-&gt;<\/span>getMessage<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n    echo <span style=\"color: #ff0000;\">'\u041e\u0448\u0438\u0431\u043a\u0430: \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span>\r\n?<span style=\"color: #66cc66;\">&gt;<\/span><\/pre>\n<p><strong>\u0417\u0430\u0447\u0435\u043c \u0442\u0430\u043a \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e:<\/strong><\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <code class=\"CodeInlined\">SELECT<\/code> \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u00ab\u0442\u0438\u0445\u0438\u0445\u00bb \u043e\u0448\u0438\u0431\u043e\u043a, \u0435\u0441\u043b\u0438 <code class=\"CodeInlined\">id<\/code> \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 (\u0432 MySQL <code class=\"CodeInlined\">UPDATE<\/code> \u0431\u0435\u0437 \u0441\u0442\u0440\u043e\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u0440\u043d\u0451\u0442 <code class=\"CodeInlined\">rowCount() = 0<\/code>, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e).<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <code class=\"CodeInlined\">$affected === 1<\/code> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0430\u0441\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430, \u0430 \u043d\u0435 \u043d\u043e\u043b\u044c \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435.<\/li>\n<\/ul>\n<hr \/>\n<h2>DELETE: \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0438 \u0437\u0430\u0449\u0438\u0442\u043e\u0439<\/h2>\n<h3>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439<\/h3>\n<p>\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e <code class=\"CodeInlined\">id<\/code>, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043e\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0430 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430.<\/p>\n<h3>SQL<\/h3>\n<pre class=\"sql\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #993333; font-weight: bold;\">SELECT<\/span> id <span style=\"color: #993333; font-weight: bold;\">FROM<\/span> users <span style=\"color: #993333; font-weight: bold;\">WHERE<\/span> id <span style=\"color: #66cc66;\">=<\/span> :id;\r\n\u00a0\r\n<span style=\"color: #993333; font-weight: bold;\">DELETE<\/span> <span style=\"color: #993333; font-weight: bold;\">FROM<\/span> users <span style=\"color: #993333; font-weight: bold;\">WHERE<\/span> id <span style=\"color: #66cc66;\">=<\/span> :id;<\/pre>\n<h3>PHP-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<pre class=\"sql\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #66cc66;\">&lt;<\/span>?php\r\ntry <span style=\"color: #66cc66;\">{<\/span>\r\n    $pdo <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> PDO<span style=\"color: #66cc66;\">(<\/span>$dsn<span style=\"color: #66cc66;\">,<\/span> $user<span style=\"color: #66cc66;\">,<\/span> $pass<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #66cc66;\">[<\/span>\r\n        PDO::ATTR_ERRMODE            <span style=\"color: #66cc66;\">=&gt;<\/span> PDO::ERRMODE_EXCEPTION<span style=\"color: #66cc66;\">,<\/span>\r\n        PDO::ATTR_DEFAULT_FETCH_MODE <span style=\"color: #66cc66;\">=&gt;<\/span> PDO::FETCH_ASSOC<span style=\"color: #66cc66;\">,<\/span>\r\n    <span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    $id <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #cc66cc;\">123<\/span>;\r\n\u00a0\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0428\u0430\u0433 <span style=\"color: #cc66cc;\">1<\/span>: \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f\r\n    $stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'SELECT id FROM users WHERE id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">':id'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $row <span style=\"color: #66cc66;\">=<\/span> $stmt<span style=\"color: #66cc66;\">-&gt;<\/span>fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    <span style=\"color: #993333; font-weight: bold;\">IF<\/span> <span style=\"color: #66cc66;\">(<\/span>!$row<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n        throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> Exception<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0428\u0430\u0433 <span style=\"color: #cc66cc;\">2<\/span>: \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <span style=\"color: #993333; font-weight: bold;\">DELETE<\/span>\r\n    $stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'DELETE FROM users WHERE id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">':id'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0428\u0430\u0433 <span style=\"color: #cc66cc;\">3<\/span>: \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\r\n    $deleted <span style=\"color: #66cc66;\">=<\/span> $stmt<span style=\"color: #66cc66;\">-&gt;<\/span>rowCount<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #993333; font-weight: bold;\">IF<\/span> <span style=\"color: #66cc66;\">(<\/span>$deleted !<span style=\"color: #66cc66;\">==<\/span> <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n        throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> Exception<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e: \u0443\u0434\u0430\u043b\u0435\u043d\u043e \u0441\u0442\u0440\u043e\u043a: '<\/span> <span style=\"color: #66cc66;\">.<\/span> $deleted<span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n    echo <span style=\"color: #ff0000;\">'\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0443\u0434\u0430\u043b\u0451\u043d.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span> catch <span style=\"color: #66cc66;\">(<\/span>Exception $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    echo <span style=\"color: #ff0000;\">'\u041e\u0448\u0438\u0431\u043a\u0430: \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span>\r\n?<span style=\"color: #66cc66;\">&gt;<\/span><\/pre>\n<hr \/>\n<h2>\u0427\u0430\u0441\u0442\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u043a\u0430\u043a \u0438\u0445 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u041e\u0448\u0438\u0431\u043a\u0430<\/th>\n<th>\u041a\u0430\u043a \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f<\/th>\n<th>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code class=\"CodeInlined\">UPDATE\/DELETE<\/code> \u0431\u0435\u0437 <code class=\"CodeInlined\">WHERE<\/code><\/td>\n<td>\u041c\u0435\u043d\u044f\u044e\u0442\u0441\u044f\/\u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/td>\n<td>\u0412\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 <code class=\"CodeInlined\">WHERE<\/code> \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c (<code class=\"CodeInlined\">id<\/code>)<\/td>\n<\/tr>\n<tr>\n<td>\u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <code class=\"CodeInlined\">rowCount()<\/code><\/td>\n<td>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u00ab\u0432\u0440\u043e\u0434\u0435 \u043f\u0440\u043e\u0448\u043b\u0430\u00bb, \u043d\u043e \u0441\u0442\u0440\u043e\u043a \u043d\u0435 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u043e<\/td>\n<td>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435 <code class=\"CodeInlined\">$stmt-&gt;rowCount()<\/code> \u0438 \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0439\u0442\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u043e 1<\/td>\n<\/tr>\n<tr>\n<td>\u041f\u0440\u044f\u043c\u0430\u044f \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 SQL<\/td>\n<td>\u0423\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u044c \u043a SQL\u2011\u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044f\u043c<\/td>\n<td>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f (<code class=\"CodeInlined\">prepare<\/code> + <code class=\"CodeInlined\">execute<\/code>)<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f<\/td>\n<td>\u041b\u043e\u0433\u0438\u043a\u0430 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 ID \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d<\/td>\n<td>\u0414\u0435\u043b\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <code class=\"CodeInlined\">SELECT<\/code> \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043e\u0432\u0435\u0442: \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e (\u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434)<\/h2>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e <code class=\"CodeInlined\">SELECT<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <code class=\"CodeInlined\">UPDATE\/DELETE<\/code> \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442 <code class=\"CodeInlined\">rowCount()<\/code>:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">php<\/div>\n<pre class=\"sql\" style=\"font-family: monospace; font-size: 14px;\">$stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'UPDATE users SET email = :email WHERE id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n$stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">':email'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $email<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #ff0000;\">':id'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n$affected <span style=\"color: #66cc66;\">=<\/span> $stmt<span style=\"color: #66cc66;\">-&gt;<\/span>rowCount<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n<span style=\"color: #993333; font-weight: bold;\">IF<\/span> <span style=\"color: #66cc66;\">(<\/span>$affected <span style=\"color: #66cc66;\">===<\/span> <span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> Exception<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u0417\u0430\u043f\u0438\u0441\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u0430 \u0438\u043b\u0438 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0430.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span> <span style=\"color: #993333; font-weight: bold;\">ELSEIF<\/span> <span style=\"color: #66cc66;\">(<\/span>$affected <span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> Exception<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u2014 \u044d\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430 \u043b\u043e\u0433\u0438\u043a\u0438.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a\u043e\u0440\u043e\u0447\u0435, \u043d\u043e \u043c\u0435\u043d\u0435\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u0435\u043d \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435: \u0432\u044b \u043d\u0435 \u0432\u0438\u0434\u0438\u0442\u0435 \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c. \u0414\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043b\u0443\u0447\u0448\u0435 \u044f\u0432\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<hr \/>\n<h2>\u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438: \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u00a0\u2014\u00a0\u0447\u0430\u0441\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u00ab\u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0432\u0441\u0435 \u0435\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u044b\u00bb), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">php<\/div>\n<pre class=\"sql\" style=\"font-family: monospace; font-size: 14px;\">$pdo<span style=\"color: #66cc66;\">-&gt;<\/span>beginTransaction<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\ntry <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0430\u0437\u043e\u0432\r\n    $stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'DELETE FROM orders WHERE user_id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">':id'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\r\n    $stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'DELETE FROM users WHERE id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">':id'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    $pdo<span style=\"color: #66cc66;\">-&gt;<\/span>commit<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span> catch <span style=\"color: #66cc66;\">(<\/span>Exception $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">ROLLBACK<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438\r\n    echo <span style=\"color: #ff0000;\">'\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u0430 \u0438\u0437-\u0437\u0430 \u043e\u0448\u0438\u0431\u043a\u0438.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439:<\/strong><\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u0412\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041f\u0440\u0438 \u043b\u044e\u0431\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 <code class=\"CodeInlined\">rollBack()<\/code>.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041d\u0435 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0439\u0442\u0435 DDL (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code class=\"CodeInlined\">CREATE TABLE<\/code>) \u0438 DML (<code class=\"CodeInlined\">UPDATE\/DELETE<\/code>) \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438\u00a0\u2014\u00a0\u0432 MySQL \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 DDL \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u044e\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439<\/h2>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">php<\/div>\n<pre class=\"sql\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #66cc66;\">&lt;<\/span>?php\r\n<span style=\"color: #993333; font-weight: bold;\">FUNCTION<\/span> updateUserEmail<span style=\"color: #66cc66;\">(<\/span>PDO $pdo<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #993333; font-weight: bold;\">INT<\/span> $id<span style=\"color: #66cc66;\">,<\/span> string $email<span style=\"color: #66cc66;\">)<\/span>: bool\r\n<span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #66cc66;\">\/\/<\/span> \u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0430 email\r\n    <span style=\"color: #993333; font-weight: bold;\">IF<\/span> <span style=\"color: #66cc66;\">(<\/span>!filter_var<span style=\"color: #66cc66;\">(<\/span>$email<span style=\"color: #66cc66;\">,<\/span> FILTER_VALIDATE_EMAIL<span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n        throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> InvalidArgumentException<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 email.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n    $pdo<span style=\"color: #66cc66;\">-&gt;<\/span>beginTransaction<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    try <span style=\"color: #66cc66;\">{<\/span>\r\n        <span style=\"color: #66cc66;\">\/\/<\/span> \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f\r\n        $stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'SELECT id FROM users WHERE id = :id FOR UPDATE'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        $stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">':id'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        $row <span style=\"color: #66cc66;\">=<\/span> $stmt<span style=\"color: #66cc66;\">-&gt;<\/span>fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        <span style=\"color: #993333; font-weight: bold;\">IF<\/span> <span style=\"color: #66cc66;\">(<\/span>!$row<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n            throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> Exception<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n        <span style=\"color: #66cc66;\">\/\/<\/span> \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\r\n        $stmt <span style=\"color: #66cc66;\">=<\/span> $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">PREPARE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'UPDATE users SET email = :email WHERE id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        $stmt<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">EXECUTE<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">':email'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $email<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #ff0000;\">':id'<\/span> <span style=\"color: #66cc66;\">=&gt;<\/span> $id<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n        <span style=\"color: #993333; font-weight: bold;\">IF<\/span> <span style=\"color: #66cc66;\">(<\/span>$stmt<span style=\"color: #66cc66;\">-&gt;<\/span>rowCount<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span> !<span style=\"color: #66cc66;\">==<\/span> <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n            throw <span style=\"color: #993333; font-weight: bold;\">NEW<\/span> Exception<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u043e.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n        $pdo<span style=\"color: #66cc66;\">-&gt;<\/span>commit<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        <span style=\"color: #993333; font-weight: bold;\">RETURN<\/span> <span style=\"color: #993333; font-weight: bold;\">TRUE<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span> catch <span style=\"color: #66cc66;\">(<\/span>Exception $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n        $pdo<span style=\"color: #66cc66;\">-&gt;<\/span><span style=\"color: #993333; font-weight: bold;\">ROLLBACK<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        throw $e;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n<span style=\"color: #66cc66;\">}<\/span>\r\n?<span style=\"color: #66cc66;\">&gt;<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><code class=\"CodeInlined\">FOR UPDATE<\/code> \u0432 <code class=\"CodeInlined\">SELECT<\/code> \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.<\/p>\n<hr \/>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u0412\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code class=\"CodeInlined\">WHERE<\/code> \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0435\u0440\u0435\u0434 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u043b\u0438\u0431\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 <code class=\"CodeInlined\">rowCount()<\/code>.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 SQL\u2011\u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0414\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0441 <code class=\"CodeInlined\">commit\/rollBack<\/code>.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u041b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u043e \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0439\u0442\u0435 \u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f (UPDATE) \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f (DELETE) \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MySQL \u0447\u0435\u0440\u0435\u0437 PHP \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c PDO. \u041e\u0441\u043e\u0431\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0443\u0434\u0435\u043b\u0435\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430\u043c: \u043d\u0430\u043b\u0438\u0447\u0438\u044e \u0437\u0430\u043f\u0438\u0441\u0438, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0438 \u0437\u0430\u0449\u0438\u0442\u0435 \u043e\u0442 \u043e\u0448\u0438\u0431\u043e\u043a. \u0412\u0430\u0436\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e: \u0431\u0435\u0437 WHERE \u2014 \u043d\u0435\u043b\u044c\u0437\u044f \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 UPDATE \u0438 DELETE \u0431\u0435\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u044f WHERE \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a\u043e \u0432\u0441\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u041e\u0434\u043d\u0430 \u043e\u043f\u0435\u0447\u0430\u0442\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0435\u0440\u0435\u0442\u044c \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u0442\u044c [&hellip;]<\/p>\n","protected":false},"author":9194254,"featured_media":135335,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[],"class_list":["post-135338","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"views":7,"_links":{"self":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/users\/9194254"}],"replies":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135338"}],"version-history":[{"count":1,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135338\/revisions"}],"predecessor-version":[{"id":135339,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135338\/revisions\/135339"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/media\/135335"}],"wp:attachment":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}