{"id":412,"date":"2021-02-13T22:31:00","date_gmt":"2021-02-13T22:31:00","guid":{"rendered":"https:\/\/rishikantsri.in\/blog\/?p=412"},"modified":"2023-10-12T09:44:54","modified_gmt":"2023-10-12T09:44:54","slug":"basic-and-advance-feature-of-mysqli","status":"publish","type":"post","link":"https:\/\/rishikantsri.in\/blog\/basic-and-advance-feature-of-mysqli\/","title":{"rendered":"Basic and Advance feature of MySqli"},"content":{"rendered":"\n<p><strong>MySQLi (MySQL Improved)<\/strong> is a PHP extension for interacting with MySQL databases. It provides both procedural and object-oriented programming interfaces and offers a wide range of features for database operations. Below, I&#8217;ll cover some basic and advanced features of MySQLi 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 MySQL database, use <code>mysqli_connect()<\/code> (procedural) or <code>new mysqli()<\/code> (object-oriented).<\/li>\n\n\n\n<li><\/li>\n<\/ol>\n\n\n\n<p><strong>Procedural Example:<\/strong><\/p>\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=\"   $conn = mysqli_connect(&quot;localhost&quot;, &quot;username&quot;, &quot;password&quot;, &quot;database_name&quot;);\n   if (!$conn) {\n       die(&quot;Connection failed: &quot; . mysqli_connect_error());\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\">   $conn <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> mysqli_connect<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&quot;localhost&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;username&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;password&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;database_name&quot;<\/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\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #B392F0\">$conn) {<\/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\"> mysqli_connect_error<\/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<p><strong>Object-Oriented Example:<\/strong><\/p>\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=\"   $conn = new mysqli(&quot;localhost&quot;, &quot;username&quot;, &quot;password&quot;, &quot;database_name&quot;);\n   if ($conn-&gt;connect_error) {\n       die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);\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\">   $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\">mysqli<\/span><span style=\"color: #B392F0\">(<\/span><span style=\"color: #FFAB70\">&quot;localhost&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;username&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;password&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;database_name&quot;<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> ($conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">connect_error) {<\/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\"> $conn<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">connect_error);<\/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 <code>mysqli_query()<\/code> for procedural style and <code>$conn->query()<\/code> for object-oriented style. <\/li>\n<\/ol>\n\n\n\n<p><strong>Procedural Example:<\/strong><\/p>\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   $result = mysqli_query($conn, $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\">   $result <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> mysqli_query<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$conn<\/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<p><strong>Object-Oriented Example:<\/strong><\/p>\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   $result = $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\">   $result <\/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>: You can fetch data using functions like <code>mysqli_fetch_assoc()<\/code>, <code>mysqli_fetch_row()<\/code>, and others for the procedural style, or <code>$result->fetch_assoc()<\/code>, <code>$result->fetch_row()<\/code>, etc., for the object-oriented style. <\/li>\n<\/ol>\n\n\n\n<p><strong>Procedural Example:<\/strong><\/p>\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 = mysqli_fetch_assoc($result)) {\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\"> mysqli_fetch_assoc<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$result<\/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<p><strong>Object-Oriented Example:<\/strong><\/p>\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 = $result-&gt;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\"> $result<\/span><span style=\"color: #F97583\">-&gt;<\/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>: MySQLi supports prepared statements for safe and efficient queries. Here&#8217;s an example of a prepared statement for selecting data:<\/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;SELECT username, email FROM users WHERE id = ?&quot;;\n   $stmt = $conn-&gt;prepare($sql);\n   $id = 1;\n   $stmt-&gt;bind_param(&quot;i&quot;, $id); \/\/ &quot;i&quot; represents an integer\n   $stmt-&gt;execute();\n   $stmt-&gt;bind_result($username, $email);\n   $stmt-&gt;fetch();\" 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\"> ?&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\">   $id <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">1<\/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\">bind_param<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&quot;i&quot;<\/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: #6B737C\">\/\/ &quot;i&quot; represents an integer<\/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\">   $stmt<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">bind_result<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$username<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $email<\/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\">fetch<\/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>: MySQLi provides detailed error handling through functions like <code>mysqli_error()<\/code> and <code>mysqli_errno()<\/code> for procedural style and via <code>$conn-&gt;error<\/code> and <code>$conn-&gt;errno<\/code> for object-oriented style.<\/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=\"   if ($result === false) {\n       echo &quot;Error: &quot; . mysqli_error($conn);\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\">if<\/span><span style=\"color: #B392F0\"> ($result <\/span><span style=\"color: #F97583\">===<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">false<\/span><span style=\"color: #B392F0\">) {<\/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\"> mysqli_error<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$conn<\/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>: MySQLi supports transactions. You can begin a transaction with <code>mysqli_begin_transaction()<\/code> (procedural) or <code>$conn-&gt;begin_transaction()<\/code> (object-oriented) and commit or rollback as needed.<\/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=\"   mysqli_begin_transaction($conn);\n   \/\/ Perform database operations\n   if (\/* Operation successful *\/) {\n       mysqli_commit($conn);\n   } else {\n       mysqli_rollback($conn);\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\">   mysqli_begin_transaction<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$conn<\/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\">   <\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #6B737C\">\/* Operation successful *\/<\/span><span style=\"color: #B392F0\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       mysqli_commit<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$conn<\/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\">else<\/span><span style=\"color: #B392F0\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">       mysqli_rollback<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #B392F0\">$conn<\/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>Stored Procedures<\/strong>: You can call stored procedures using MySQLi, both for prepared statements and regular queries.<\/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(?, ?)&quot;;\n   $stmt = $conn-&gt;prepare($sql);\n   $param1 = 1;\n   $param2 = &quot;example&quot;;\n   $stmt-&gt;bind_param(&quot;is&quot;, $param1, $param2);\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(?, ?)&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\">   $param1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">1<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $param2 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;example&quot;<\/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\">bind_param<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&quot;is&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $param1<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> $param2<\/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=\"4\">\n<li><strong>Multiple Statements<\/strong>: MySQLi allows executing multiple SQL statements in a single call. Be cautious and validate input to prevent SQL injection in such cases.<\/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;INSERT INTO table1 VALUES ('value1'); INSERT INTO table2 VALUES ('value2')&quot;;\n   $conn-&gt;multi_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\">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\">multi_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=\"5\">\n<li><strong>Connection Handling<\/strong>: MySQLi supports managing multiple database connections and connection pooling.<\/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=\"   $conn1 = new mysqli(&quot;host1&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;db1&quot;);\n   $conn2 = new mysqli(&quot;host2&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;db2&quot;);\n   \/\/ Perform operations with $conn1 and $conn2\n   $conn1-&gt;close();\n   $conn2-&gt;close();\" 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\">   $conn1 <\/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\">mysqli<\/span><span style=\"color: #B392F0\">(<\/span><span style=\"color: #FFAB70\">&quot;host1&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;user&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;pass&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;db1&quot;<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $conn2 <\/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\">mysqli<\/span><span style=\"color: #B392F0\">(<\/span><span style=\"color: #FFAB70\">&quot;host2&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;user&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;pass&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;db2&quot;<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   <\/span><span style=\"color: #6B737C\">\/\/ Perform operations with $conn1 and $conn2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $conn1<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">close<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   $conn2<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">close<\/span><span style=\"color: #BBBBBB\">()<\/span><span style=\"color: #B392F0\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This is just an overview of some basic and advanced features of MySQLi. In real-world applications, you&#8217;ll often combine these features to interact with your database efficiently and securely. MySQLi is a powerful extension for PHP that is widely used for working with MySQL databases.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQLi (MySQL Improved) is a PHP extension for interacting with MySQL databases. It provides both procedural and object-oriented programming interfaces and offers a wide range of features for database operations. Below, I&#8217;ll cover some basic and advanced features of MySQLi along with examples. Basic Features: Procedural Example: Object-Oriented Example: Procedural Example: Object-Oriented Example: Procedural Example: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,10],"tags":[51,4],"_links":{"self":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/412"}],"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=412"}],"version-history":[{"count":2,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":415,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions\/415"}],"wp:attachment":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/categories?post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/tags?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}