{"id":418,"date":"2021-02-20T22:58:00","date_gmt":"2021-02-20T22:58:00","guid":{"rendered":"https:\/\/rishikantsri.in\/blog\/?p=418"},"modified":"2023-10-13T06:00:42","modified_gmt":"2023-10-13T06:00:42","slug":"basic-and-advance-feature-of-php-pdo","status":"publish","type":"post","link":"https:\/\/rishikantsri.in\/blog\/basic-and-advance-feature-of-php-pdo\/","title":{"rendered":"Basic and Advance feature of PHP PDO"},"content":{"rendered":"\n<p>PHP PDO (PHP Data Objects) is a versatile database access extension that allows developers to interact with various database systems using a consistent and secure interface. It offers a wide range of features for database operations. Below, I&#8217;ll cover some basic and advanced features of PHP PDO along with examples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Features:<\/h3>\n\n\n\n<ol>\n<li><strong>Connection<\/strong>: To establish a connection to a database, use the <code>PDO<\/code> constructor. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887496948242188px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   $dsn = &quot;mysql:host=localhost;dbname=database_name&quot;;\n   $username = &quot;username&quot;;\n   $password = &quot;password&quot;;\n\n   try {\n       $conn = new PDO($dsn, $username, $password);\n   } catch (PDOException $e) {\n       die(&quot;Connection failed: &quot; . $e-&gt;getMessage());\n   }\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   $dsn <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;mysql:host=localhost;dbname=database_name&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $username <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;username&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $password <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;password&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   <\/span><span style=\"color: #F97583\">try<\/span><span style=\"color: #B392F0\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       $conn <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #B392F0\">($dsn<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $username<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $password);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   } <\/span><span style=\"color: #F97583\">catch<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">PDOException<\/span><span style=\"color: #B392F0\"> $e) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       <\/span><span style=\"color: #F97583\">die<\/span><span style=\"color: #B392F0\">(<\/span><span style=\"color: #FFAB70\">&quot;Connection failed: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">.<\/span><span style=\"color: #B392F0\"> $e<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">getMessage<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"2\">\n<li><strong>Query Execution<\/strong>: You can execute SQL queries using the <code>query()<\/code> method. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887481689453125px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   $sql = &quot;SELECT * FROM users&quot;;\n   $stmt = $conn-&gt;query($sql);\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   $sql <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;<\/span><span style=\"color: #F97583\">SELECT<\/span><span style=\"color: #FFAB70\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #FFAB70\"> <\/span><span style=\"color: #F97583\">FROM<\/span><span style=\"color: #FFAB70\"> users&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">query<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$sql<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"3\">\n<li><strong>Fetching Data<\/strong>: Use the <code>fetch()<\/code> method to retrieve data. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887496948242188px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {\n       echo &quot;Username: &quot; . $row['username'] . &quot;&lt;br&gt;&quot;;\n   }\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   <\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #B392F0\"> ($row <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">fetch<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">FETCH_ASSOC<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       echo <\/span><span style=\"color: #FFAB70\">&quot;Username: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">.<\/span><span style=\"color: #B392F0\"> $row[<\/span><span style=\"color: #FFAB70\">&#39;username&#39;<\/span><span style=\"color: #B392F0\">] <\/span><span style=\"color: #F97583\">.<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;&lt;br&gt;&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"4\">\n<li><strong>Prepared Statements<\/strong>: PDO supports prepared statements for secure queries. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887481689453125px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   $sql = &quot;SELECT username, email FROM users WHERE id = :id&quot;;\n   $stmt = $conn-&gt;prepare($sql);\n   $stmt-&gt;bindParam(':id', $id, PDO::PARAM_INT);\n   $stmt-&gt;execute();\n   $result = $stmt-&gt;fetch(PDO::FETCH_ASSOC);\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   $sql <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;<\/span><span style=\"color: #F97583\">SELECT<\/span><span style=\"color: #FFAB70\"> username, email <\/span><span style=\"color: #F97583\">FROM<\/span><span style=\"color: #FFAB70\"> users <\/span><span style=\"color: #F97583\">WHERE<\/span><span style=\"color: #FFAB70\"> id <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #FFAB70\"> :id&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">prepare<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$sql<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">bindParam<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;:id&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $id<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">PARAM_INT<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">execute<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $result <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">fetch<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">FETCH_ASSOC<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Features:<\/h3>\n\n\n\n<ol>\n<li><strong>Error Handling<\/strong>: PDO offers robust error handling through exceptions. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887496948242188px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   try {\n       \/\/ Database operations\n   } catch (PDOException $e) {\n       echo &quot;Error: &quot; . $e-&gt;getMessage();\n   }\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   <\/span><span style=\"color: #F97583\">try<\/span><span style=\"color: #B392F0\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       <\/span><span style=\"color: #6B737C\">\/\/ Database operations<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   } <\/span><span style=\"color: #F97583\">catch<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">PDOException<\/span><span style=\"color: #B392F0\"> $e) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       echo <\/span><span style=\"color: #FFAB70\">&quot;Error: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">.<\/span><span style=\"color: #B392F0\"> $e<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">getMessage<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"2\">\n<li><strong>Transactions<\/strong>: PDO supports transactions. You can use <code>beginTransaction()<\/code>, <code>commit()<\/code>, and <code>rollBack()<\/code> to handle transactions. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887496948242188px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   try {\n       $conn-&gt;beginTransaction();\n       \/\/ Perform database operations\n       $conn-&gt;commit();\n   } catch (PDOException $e) {\n       $conn-&gt;rollBack();\n       echo &quot;Transaction failed: &quot; . $e-&gt;getMessage();\n   }\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   <\/span><span style=\"color: #F97583\">try<\/span><span style=\"color: #B392F0\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">beginTransaction<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       <\/span><span style=\"color: #6B737C\">\/\/ Perform database operations<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">commit<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   } <\/span><span style=\"color: #F97583\">catch<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">PDOException<\/span><span style=\"color: #B392F0\"> $e) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">rollBack<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       echo <\/span><span style=\"color: #FFAB70\">&quot;Transaction failed: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">.<\/span><span style=\"color: #B392F0\"> $e<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">getMessage<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"3\">\n<li><strong>Named Placeholders<\/strong>: PDO allows the use of named placeholders in prepared statements. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887451171875px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   $sql = &quot;INSERT INTO table (column1, column2) VALUES (:value1, :value2)&quot;;\n   $stmt = $conn-&gt;prepare($sql);\n   $stmt-&gt;bindParam(':value1', $value1, PDO::PARAM_STR);\n   $stmt-&gt;bindParam(':value2', $value2, PDO::PARAM_INT);\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   $sql <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;<\/span><span style=\"color: #F97583\">INSERT INTO<\/span><span style=\"color: #FFAB70\"> <\/span><span style=\"color: #F97583\">table<\/span><span style=\"color: #FFAB70\"> (column1, column2) <\/span><span style=\"color: #F97583\">VALUES<\/span><span style=\"color: #FFAB70\"> (:value1, :value2)&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">prepare<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$sql<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">bindParam<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;:value1&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $value1<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">PARAM_STR<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">bindParam<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;:value2&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $value2<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">PARAM_INT<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"4\">\n<li><strong>Multiple Statements<\/strong>: PDO can execute multiple SQL statements in a single call. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887496948242188px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   $sql = &quot;INSERT INTO table1 VALUES ('value1'); INSERT INTO table2 VALUES ('value2')&quot;;\n   $conn-&gt;exec($sql);\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   $sql <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;<\/span><span style=\"color: #F97583\">INSERT INTO<\/span><span style=\"color: #FFAB70\"> table1 <\/span><span style=\"color: #F97583\">VALUES<\/span><span style=\"color: #FFAB70\"> (&#39;value1&#39;); <\/span><span style=\"color: #F97583\">INSERT INTO<\/span><span style=\"color: #FFAB70\"> table2 <\/span><span style=\"color: #F97583\">VALUES<\/span><span style=\"color: #FFAB70\"> (&#39;value2&#39;)&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">exec<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$sql<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"5\">\n<li><strong>Stored Procedures<\/strong>: You can call stored procedures using PDO. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.887496948242188px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   $sql = &quot;CALL procedure_name(:param1, :param2)&quot;;\n   $stmt = $conn-&gt;prepare($sql);\n   $stmt-&gt;bindParam(':param1', $param1, PDO::PARAM_INT);\n   $stmt-&gt;bindParam(':param2', $param2, PDO::PARAM_STR);\n   $stmt-&gt;execute();\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   $sql <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;CALL procedure_name(:param1, :param2)&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">prepare<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$sql<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">bindParam<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;:param1&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $param1<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">PARAM_INT<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">bindParam<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;:param2&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $param2<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">PARAM_STR<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">execute<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"6\">\n<li><strong>Database Independence<\/strong>: PDO allows you to switch between different database systems by changing the DSN, making it database-independent. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.88751220703125px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   \/\/ Switching to SQLite\n   $dsn = &quot;sqlite:\/path\/to\/database.db&quot;;\n   $conn = new PDO($dsn);\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   <\/span><span style=\"color: #6B737C\">\/\/ Switching to SQLite<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $dsn <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;sqlite:\/path\/to\/database.db&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $conn <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #B392F0\">($dsn);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"7\">\n<li><strong>Attribute Setting<\/strong>: You can set various attributes for your PDO connection, such as error handling and emulation mode. <strong>Example:<\/strong><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.88751220703125px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n   $conn-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">setAttribute<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">ATTR_ERRMODE<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">ERRMODE_EXCEPTION<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">setAttribute<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #79B8FF\">PDO<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">ATTR_EMULATE_PREPARES<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">false<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This is a broad overview of some basic and advanced features of PHP PDO. In practice, you can combine these features to perform complex database operations securely and efficiently. PHP PDO is a powerful and flexible extension that can be used with various database systems, and it is a popular choice for working with databases in PHP applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP PDO (PHP Data Objects) is a versatile database access extension that allows developers to interact with various database systems using a consistent and secure interface. It offers a wide range of features for database operations. Below, I&#8217;ll cover some basic and advanced features of PHP PDO along with examples. Basic Features: Advanced Features: This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,10],"tags":[49,4],"_links":{"self":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/418"}],"collection":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/comments?post=418"}],"version-history":[{"count":1,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/418\/revisions"}],"predecessor-version":[{"id":419,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/418\/revisions\/419"}],"wp:attachment":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/media?parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/categories?post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/tags?post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}