{"id":135637,"date":"2026-08-31T11:01:46","date_gmt":"2026-08-31T05:01:46","guid":{"rendered":"https:\/\/rcl-radio.ru\/?p=135637"},"modified":"2026-08-31T11:01:46","modified_gmt":"2026-08-31T05:01:46","slug":"%d0%ba%d0%b0%d0%ba-%d0%b1%d0%b5%d0%b7%d0%be%d0%bf%d0%b0%d1%81%d0%bd%d0%be-%d0%be%d0%b1%d1%80%d0%b0%d0%b1%d0%b0%d1%82%d1%8b%d0%b2%d0%b0%d1%82%d1%8c-%d0%be%d1%88%d0%b8%d0%b1%d0%ba%d0%b8-pdo-%d0%bf%d1%80","status":"publish","type":"post","link":"https:\/\/rcl-radio.ru\/?p=135637","title":{"rendered":"\u041a\u0430\u043a \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 PDO \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 MySQL"},"content":{"rendered":"<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 PDO \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u2014 \u044d\u0442\u043e \u0440\u0438\u0441\u043a: \u043f\u0440\u0438 \u0441\u0431\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0432\u0438\u0434\u0438\u0442 \u043b\u0438\u0431\u043e \u043f\u0443\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043b\u0438\u0431\u043e \u00ab500 Internal Server Error\u00bb, \u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0435 \u043f\u043e\u0439\u043c\u0451\u0442, \u0432 \u0447\u0451\u043c \u0434\u0435\u043b\u043e. \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0442\u0438\u0445\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043b\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438.<\/p>\n<hr \/>\n<h2>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e: \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e SQL\u2011\u043e\u0448\u0438\u0431\u043a\u0438<\/h2>\n<p>SQL\u2011\u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0438\u043c\u0435\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446, \u043a\u043e\u043b\u043e\u043d\u043e\u043a, \u0438\u043d\u043e\u0433\u0434\u0430 \u0447\u0430\u0441\u0442\u0438 \u043b\u043e\u0433\u0438\u043a\u0438. \u0418\u0445 \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0435\u0439\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u0440\u043e\u0434\u0435 \u00ab\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u043e\u0437\u0436\u0435\u00bb. \u0410 \u0432\u0441\u0451 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043b\u043e\u0433.<\/p>\n<hr \/>\n<h2>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u043e\u0448\u0438\u0431\u043e\u043a \u0432 PDO<\/h2>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 <code class=\"CodeInlined\">PDO::ERRMODE_EXCEPTION<\/code>. \u0422\u043e\u0433\u0434\u0430 \u043b\u044e\u0431\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0431\u0430\u0437\u044b \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c.<\/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=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\">$dsn = <span style=\"color: #ff0000;\">'mysql:host=localhost;dbname=test;charset=utf8mb4'<\/span>;\r\n$user = <span style=\"color: #ff0000;\">'user'<\/span>;\r\n$pass = <span style=\"color: #ff0000;\">'pass'<\/span>;\r\n\u00a0\r\n$options = <span style=\"color: #66cc66;\">[<\/span>\r\n    PDO::ATTR_ERRMODE            =<span style=\"color: #66cc66;\">&gt;<\/span> PDO::ERRMODE_EXCEPTION,\r\n    PDO::ATTR_DEFAULT_FETCH_MODE =<span style=\"color: #66cc66;\">&gt;<\/span> PDO::FETCH_ASSOC,\r\n    PDO::ATTR_EMULATE_PREPARES   =<span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #000000; font-weight: bold;\">false<\/span>,\r\n<span style=\"color: #66cc66;\">]<\/span>;\r\n\u00a0\r\n<span style=\"color: #0066cc;\">try<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    $pdo = <span style=\"color: #000000; font-weight: bold;\">new<\/span> PDO<span style=\"color: #66cc66;\">(<\/span>$dsn, $user, $pass, $options<span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span> <span style=\"color: #0066cc;\">catch<\/span> <span style=\"color: #66cc66;\">(<\/span>PDOException $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #808080; font-style: italic;\">\/\/ \u041b\u043e\u0433\u0438\u0440\u0443\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u2014 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c<\/span>\r\n    error_log<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'DB connection failed: '<\/span> . $e-<span style=\"color: #66cc66;\">&gt;<\/span>getMessage<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    die<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e <code class=\"CodeInlined\">ERRMODE_EXCEPTION<\/code>:<\/strong><\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u041f\u0440\u043e\u0449\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a: \u0432\u0441\u0451 \u043f\u0430\u0434\u0430\u0435\u0442 \u0432 <code class=\"CodeInlined\">catch<\/code>, \u043d\u0435\u0442 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430\u043c\u0438.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0423\u0434\u043e\u0431\u043d\u043e \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0441\u0432\u043e\u0438 \u0431\u043b\u043e\u043a\u0438 <code class=\"CodeInlined\">try\/catch<\/code>, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u2011\u0440\u0430\u0437\u043d\u043e\u043c\u0443 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438<\/h2>\n<p>\u0412 \u043b\u043e\u0433 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043d\u043e \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442: \u0442\u0438\u043f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b (\u0431\u0435\u0437 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445), \u0441\u0442\u0435\u043a.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/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=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #000000; font-weight: bold;\">function<\/span> logDbError<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">string<\/span> $context, \\Throwable $e<span style=\"color: #66cc66;\">)<\/span>: <span style=\"color: #0066cc;\">void<\/span>\r\n<span style=\"color: #66cc66;\">{<\/span>\r\n    $message = sprintf<span style=\"color: #66cc66;\">(<\/span>\r\n        <span style=\"color: #ff0000;\">'[DB] %s | Message: %s | Code: %s | Trace: %s'<\/span>,\r\n        $context,\r\n        $e-<span style=\"color: #66cc66;\">&gt;<\/span>getMessage<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>,\r\n        $e-<span style=\"color: #66cc66;\">&gt;<\/span><span style=\"color: #0066cc;\">getCode<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>,\r\n        $e-<span style=\"color: #66cc66;\">&gt;<\/span>getTraceAsString<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n    <span style=\"color: #66cc66;\">)<\/span>;\r\n    error_log<span style=\"color: #66cc66;\">(<\/span>$message<span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0451 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445:<\/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=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #0066cc;\">try<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    $stmt = $pdo-<span style=\"color: #66cc66;\">&gt;<\/span>prepare<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'SELECT * FROM users WHERE id = :id'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt-<span style=\"color: #66cc66;\">&gt;<\/span>execute<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">'id'<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> $userId<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $user = $stmt-<span style=\"color: #66cc66;\">&gt;<\/span>fetch<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span> <span style=\"color: #0066cc;\">catch<\/span> <span style=\"color: #66cc66;\">(<\/span>PDOException $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    logDbError<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'Fetch user by ID'<\/span>, $e<span style=\"color: #66cc66;\">)<\/span>;\r\n    <span style=\"color: #808080; font-style: italic;\">\/\/ \u0414\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u2014 \u043d\u0435\u0439\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435<\/span>\r\n    http_response_code<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #cc66cc;\">500<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    echo <span style=\"color: #ff0000;\">'\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u044c. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u043e\u0437\u0436\u0435.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u0427\u0442\u043e \u0432\u0430\u0436\u043d\u043e:<\/strong><\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u041d\u0435 \u043b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u0430\u0440\u043e\u043b\u0438, \u0442\u043e\u043a\u0435\u043d\u044b, \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0412 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u043b\u0443\u0447\u0448\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b \u0438\u043b\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0431\u043e\u0440\u0430 \u043b\u043e\u0433\u043e\u0432 (Monolog, Graylog, Sentry), \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 <code class=\"CodeInlined\">error_log<\/code>.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u0427\u0430\u0441\u0442\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0438 \u043a\u0430\u043a \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c<\/h2>\n<h3>1. \u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414<\/h3>\n<p>\u0423\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0432\u044b\u0448\u0435: \u043b\u043e\u0433 + \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430), \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0443 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0430\u043b\u0435\u0440\u0442 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443.<\/p>\n<h3>2. \u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438 \u0442.\u043f.)<\/h3>\n<p>\u042d\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043a\u043e\u0434\u0430, \u0430 \u043d\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041b\u043e\u0433 \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u0439\u0442\u0438 \u0431\u0430\u0433.<\/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=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #0066cc;\">try<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    $stmt = $pdo-<span style=\"color: #66cc66;\">&gt;<\/span>query<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'SELECT * FROM non_existent_table'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span> <span style=\"color: #0066cc;\">catch<\/span> <span style=\"color: #66cc66;\">(<\/span>PDOException $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    logDbError<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'Query error in dashboard stats'<\/span>, $e<span style=\"color: #66cc66;\">)<\/span>;\r\n    http_response_code<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #cc66cc;\">500<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    echo <span style=\"color: #ff0000;\">'\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<h3>3. \u041d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442, \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441)<\/h3>\n<p>\u0422\u0443\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u2014 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0443\u0436\u0435 \u0437\u0430\u043d\u044f\u0442\u044b\u043c email.<\/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=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #0066cc;\">try<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    $stmt = $pdo-<span style=\"color: #66cc66;\">&gt;<\/span>prepare<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'INSERT INTO users (email, password_hash) VALUES (:email, :pass)'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt-<span style=\"color: #66cc66;\">&gt;<\/span>execute<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,\r\n        <span style=\"color: #ff0000;\">'pass'<\/span>  =<span style=\"color: #66cc66;\">&gt;<\/span> $passwordHash,\r\n    <span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span> <span style=\"color: #0066cc;\">catch<\/span> <span style=\"color: #66cc66;\">(<\/span>PDOException $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #66cc66;\">(<\/span>$e-<span style=\"color: #66cc66;\">&gt;<\/span><span style=\"color: #0066cc;\">getCode<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span> === <span style=\"color: #ff0000;\">'23000'<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span> <span style=\"color: #808080; font-style: italic;\">\/\/ \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/span>\r\n        logDbError<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'Duplicate email on registration'<\/span>, $e<span style=\"color: #66cc66;\">)<\/span>;\r\n        http_response_code<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #cc66cc;\">409<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        echo <span style=\"color: #ff0000;\">'\u0422\u0430\u043a\u043e\u0439 email \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d.'<\/span>;\r\n        <span style=\"color: #b1b100;\">return<\/span>;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n    <span style=\"color: #808080; font-style: italic;\">\/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u2014 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e<\/span>\r\n    logDbError<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'Registration DB error'<\/span>, $e<span style=\"color: #66cc66;\">)<\/span>;\r\n    http_response_code<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #cc66cc;\">500<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    echo <span style=\"color: #ff0000;\">'\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<h3>4. \u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u043e\u0442\u043a\u0430\u0442<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0431\u0430\u0437\u0443 \u0432 \u043d\u0435\u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\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=\"actionscript\" 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\n<span style=\"color: #0066cc;\">try<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    $stmt1 = $pdo-<span style=\"color: #66cc66;\">&gt;<\/span>prepare<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'UPDATE accounts SET balance = balance - :amount WHERE id = :from'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt1-<span style=\"color: #66cc66;\">&gt;<\/span>execute<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">'amount'<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> $amount, <span style=\"color: #ff0000;\">'from'<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> $fromId<span style=\"color: #66cc66;\">]<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n\u00a0\r\n    $stmt2 = $pdo-<span style=\"color: #66cc66;\">&gt;<\/span>prepare<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'UPDATE accounts SET balance = balance + :amount WHERE id = :to'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    $stmt2-<span style=\"color: #66cc66;\">&gt;<\/span>execute<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">'amount'<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> $amount, <span style=\"color: #ff0000;\">'to'<\/span> =<span style=\"color: #66cc66;\">&gt;<\/span> $toId<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> <span style=\"color: #0066cc;\">catch<\/span> <span style=\"color: #66cc66;\">(<\/span>PDOException $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n    $pdo-<span style=\"color: #66cc66;\">&gt;<\/span>rollBack<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    logDbError<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'Transfer failed'<\/span>, $e<span style=\"color: #66cc66;\">)<\/span>;\r\n    http_response_code<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #cc66cc;\">500<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n    echo <span style=\"color: #ff0000;\">'\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u043e\u0434. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u043e\u0437\u0436\u0435.'<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<hr \/>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e\u0434 \u0432\u0430\u0448\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 (\u0430\u0434\u043c\u0438\u043d\u043a\u0438, \u0441\u0442\u0430\u0442\u044c\u0438, \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0438)<\/h2>\n<ul>\n<li data-value=\"\" data-shift=\"0\"><strong>\u0412 \u0430\u0434\u043c\u0438\u043d\u043a\u0435<\/strong> \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438\u043b\u0438 \u0442\u043e\u0432\u0430\u0440\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0411\u0414 \u2014 \u044d\u0442\u043e \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f. \u041b\u043e\u0433\u0438\u0440\u0443\u0439\u0442\u0435 \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c (ID \u0441\u0442\u0430\u0442\u044c\u0438\/\u0442\u043e\u0432\u0430\u0440\u0430, \u0442\u0438\u043f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438) \u0438 \u043f\u043e\u043a\u0430\u0436\u0438\u0442\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e: \u00ab\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c. \u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435\u0441\u044c \u043a \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443\u00bb.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u041d\u0430 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430<\/strong> \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u2014 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043b\u043e\u043c\u0430\u0442\u044c \u0432\u0441\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043b\u0438 \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0443 \u00ab\u0422\u043e\u0432\u0430\u0440\u044b \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u044b\u00bb \u0438 \u0437\u0430\u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u041f\u0440\u0438 \u043c\u0430\u0441\u0441\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445<\/strong> (\u0438\u043c\u043f\u043e\u0440\u0442, \u043f\u0435\u0440\u0435\u0441\u0447\u0451\u0442 \u0446\u0435\u043d) \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0439\u0442\u0435 \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0438\u043b\u0438 \u0431\u043b\u043e\u043a \u0432 <code class=\"CodeInlined\">try\/catch<\/code> \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0439\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044f \u0441\u0431\u043e\u0439\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438. \u0422\u0430\u043a \u0441\u0430\u0439\u0442 \u043d\u0435 \u00ab\u043f\u0430\u0434\u0430\u0435\u0442\u00bb, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u0427\u0435\u0433\u043e \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c<\/h2>\n<ul>\n<li data-value=\"\" data-shift=\"0\"><strong>\u0412\u044b\u0432\u043e\u0434\u0438\u0442\u044c <code class=\"CodeInlined\">$e-&gt;getMessage()<\/code> \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/strong> \u042d\u0442\u043e \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/strong> \u0415\u0441\u043b\u0438 \u043d\u0435 \u043b\u043e\u0432\u0438\u0442\u044c <code class=\"CodeInlined\">PDOException<\/code>, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/strong> \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043b\u043e\u0433 \u043f\u0430\u0440\u043e\u043b\u0438, \u0442\u043e\u043a\u0435\u043d\u044b, \u043f\u043e\u043b\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u0440\u0442.<\/li>\n<li data-value=\"\" data-shift=\"0\"><strong>\u0414\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e <code class=\"CodeInlined\">ERRMODE_WARNING<\/code> \u0438\u043b\u0438 <code class=\"CodeInlined\">ERRMODE_SILENT<\/code> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0449\u0435.<\/strong> \u0412 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b \u0442\u0435\u0440\u044f\u0435\u0442\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0443.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/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=\"actionscript\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #000000; font-weight: bold;\">class<\/span> Db\r\n<span style=\"color: #66cc66;\">{<\/span>\r\n    <span style=\"color: #0066cc;\">private<\/span> PDO $pdo;\r\n\u00a0\r\n    <span style=\"color: #0066cc;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">function<\/span> __construct<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n    <span style=\"color: #66cc66;\">{<\/span>\r\n        $dsn = <span style=\"color: #ff0000;\">'mysql:host=localhost;dbname=test;charset=utf8mb4'<\/span>;\r\n        $options = <span style=\"color: #66cc66;\">[<\/span>\r\n            PDO::ATTR_ERRMODE            =<span style=\"color: #66cc66;\">&gt;<\/span> PDO::ERRMODE_EXCEPTION,\r\n            PDO::ATTR_DEFAULT_FETCH_MODE =<span style=\"color: #66cc66;\">&gt;<\/span> PDO::FETCH_ASSOC,\r\n            PDO::ATTR_EMULATE_PREPARES   =<span style=\"color: #66cc66;\">&gt;<\/span> <span style=\"color: #000000; font-weight: bold;\">false<\/span>,\r\n        <span style=\"color: #66cc66;\">]<\/span>;\r\n\u00a0\r\n        <span style=\"color: #0066cc;\">try<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n            $this-<span style=\"color: #66cc66;\">&gt;<\/span>pdo = <span style=\"color: #000000; font-weight: bold;\">new<\/span> PDO<span style=\"color: #66cc66;\">(<\/span>$dsn, $_ENV<span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">'DB_USER'<\/span><span style=\"color: #66cc66;\">]<\/span>, $_ENV<span style=\"color: #66cc66;\">[<\/span><span style=\"color: #ff0000;\">'DB_PASS'<\/span><span style=\"color: #66cc66;\">]<\/span>, $options<span style=\"color: #66cc66;\">)<\/span>;\r\n        <span style=\"color: #66cc66;\">}<\/span> <span style=\"color: #0066cc;\">catch<\/span> <span style=\"color: #66cc66;\">(<\/span>PDOException $e<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\r\n            logDbError<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'DB init'<\/span>, $e<span style=\"color: #66cc66;\">)<\/span>;\r\n            die<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #ff0000;\">'\u0421\u0435\u0440\u0432\u0438\u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d.'<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n        <span style=\"color: #66cc66;\">}<\/span>\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n    <span style=\"color: #0066cc;\">public<\/span> <span style=\"color: #000000; font-weight: bold;\">function<\/span> getPdo<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>: PDO\r\n    <span style=\"color: #66cc66;\">{<\/span>\r\n        <span style=\"color: #b1b100;\">return<\/span> $this-<span style=\"color: #66cc66;\">&gt;<\/span>pdo;\r\n    <span style=\"color: #66cc66;\">}<\/span>\r\n<span style=\"color: #66cc66;\">}<\/span>\r\n\u00a0\r\n<span style=\"color: #000000; font-weight: bold;\">function<\/span> logDbError<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #0066cc;\">string<\/span> $context, \\Throwable $e<span style=\"color: #66cc66;\">)<\/span>: <span style=\"color: #0066cc;\">void<\/span>\r\n<span style=\"color: #66cc66;\">{<\/span>\r\n    error_log<span style=\"color: #66cc66;\">(<\/span>sprintf<span style=\"color: #66cc66;\">(<\/span>\r\n        <span style=\"color: #ff0000;\">'[DB] %s | %s | %s'<\/span>,\r\n        $context,\r\n        $e-<span style=\"color: #66cc66;\">&gt;<\/span>getMessage<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>,\r\n        $e-<span style=\"color: #66cc66;\">&gt;<\/span>getTraceAsString<span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span>\r\n    <span style=\"color: #66cc66;\">)<\/span><span style=\"color: #66cc66;\">)<\/span>;\r\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u0435\u043b\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code class=\"CodeInlined\">$db-&gt;getPdo()<\/code> \u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 <code class=\"CodeInlined\">try\/catch<\/code> \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code class=\"CodeInlined\">logDbError<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 PDO \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u2014 \u044d\u0442\u043e \u0440\u0438\u0441\u043a: \u043f\u0440\u0438 \u0441\u0431\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0432\u0438\u0434\u0438\u0442 \u043b\u0438\u0431\u043e \u043f\u0443\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043b\u0438\u0431\u043e \u00ab500 Internal Server Error\u00bb, \u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0435 \u043f\u043e\u0439\u043c\u0451\u0442, \u0432 \u0447\u0451\u043c \u0434\u0435\u043b\u043e. \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0442\u0438\u0445\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043b\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e: \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e SQL\u2011\u043e\u0448\u0438\u0431\u043a\u0438 SQL\u2011\u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0438\u043c\u0435\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446, [&hellip;]<\/p>\n","protected":false},"author":9194254,"featured_media":135584,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183,557],"tags":[],"class_list":["post-135637","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-557"],"views":22,"_links":{"self":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135637","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=135637"}],"version-history":[{"count":1,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135637\/revisions"}],"predecessor-version":[{"id":135638,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135637\/revisions\/135638"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/media\/135584"}],"wp:attachment":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}