How to conenct to SQL using PHP.?

I want to know that how to connect a HTML code to the SQL using PHP. I have just created a form in HTML but I don’t know how to connect it with the SQL of local server. So please help me.

Thanks in advance.

As you haven’t mentioned which database exactly you are using, I will suggest using PDO, which covers most of the common databases.

Just to be clear, are you referring to Microsoft SQL Server? Or are you using SQL as a generalized term for any Database?

I am using Xampp Server for the PHP. So I want to connet to database of this server.

Okay, you will need to know your username and password for your MySQL setup (it likely asked you this during installation)

To Connect:
To Run a Query:

@sid8 ;

If you’d like a tutorial approach, check out the latest postings from PHP Master:

You would connect as follows:


Hope this helps.

Um … no. mysql_connect is being deprecated in the next release, so definitely not. You can use mysqli, but it is still preferred to move to PDO.

thanks for the help frnds…I have done with it…

You would connect as follows:
In PHP, this is done with the mysqli_connect() function.
This is the syntax for MySQL connect through php

// Create connection

// Check connection
if (mysqli_connect_errno($con))
  echo "Failed to connect to MySQL: " . mysqli_connect_error();