<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Faraz Sheikh</title>
    <description>The latest articles on DEV Community by Faraz Sheikh (@itsfrz).</description>
    <link>https://dev.to/itsfrz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F452432%2Fead400f8-d597-4dd3-a731-c9c43606f7a2.jpeg</url>
      <title>DEV Community: Faraz Sheikh</title>
      <link>https://dev.to/itsfrz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/itsfrz"/>
    <language>en</language>
    <item>
      <title>Understand PHP | SQL Connectivity (Easily)</title>
      <dc:creator>Faraz Sheikh</dc:creator>
      <pubDate>Fri, 14 Aug 2020 13:18:36 +0000</pubDate>
      <link>https://dev.to/itsfrz/understand-php-sql-connectivity-easily-5c24</link>
      <guid>https://dev.to/itsfrz/understand-php-sql-connectivity-easily-5c24</guid>
      <description>&lt;p&gt;Hello friends, I have seen that many people facing difficulty during connectivity of PHP with SQL, So today we see how we will resolve this problem easily.&lt;/p&gt;

&lt;p&gt;Note:- Please read the whole blog to avoid any inconvenience.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Step 1 : &lt;br&gt;
Create a file or open your favorite notepad generally for programming or scripting developers use notepad++ you can use any.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 2 : &lt;br&gt;
Trigger your server or localhost if you have a XAMPP then you need to press Apache or MYSQL buttons until it will turn into green.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 3 :&lt;br&gt;
Write commands like below&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
    $servername = "localhost";
    $username = "root";
    $password = "";

    $connect = mysqli_connect($servername , $username, $password);

    if(!$connect)
    {
        die("Connection Failed".mysqli_connect_error());
    }

    echo "Connected Successfully";

    mysqli_close($connect);


?&amp;gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 4: 
Let's understand the above code
first we all know we need to write our PHP logic under &amp;lt;?php ---- ?&amp;gt; tag. So in this module, we simply declaring 3 variables that are mandatory during connectivity.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $servername = "localhost";
    $username = "root";
    $password = "";

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;variables like servername, username and password.&lt;br&gt;
This variable is used to storing our XAMPP credentials make sure you enter your credentials according to your XAMPP data.&lt;/p&gt;

&lt;p&gt;After that, We store a function that names&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysqli_connect();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;in a variable let's say $connect&lt;br&gt;
so we storing a predefined function provided by PHP in a variable to use easily and which also helps for validation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 5:
Here we connected with our SQL server, We just need to validate ourself
For validating or Ensuring we use conditional statement that provides boolean value
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(!$connect)
    {
        die("Connection Failed".mysqli_connect_error());
    }

    echo "Connected Successfully";
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we in If statement we checking if our $connect variables is negative (i.e, False) so simply call die function and write a message according to your convenience and also concatenate mysqli_connect_error() function for more satisfation using . operator which is used for concatenate in PHP.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 6:
Finally we closing our server using mysqli_close() for better practices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you learned from my post if any query visit my GitHub page for discussion.&lt;br&gt;
&lt;a href="https://github.com/ItsFRZ"&gt;ItsFRZ&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you found my work is helpfull please do share&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
