How to conenct to SQL using PHP.?

Hi
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: http://www.php.net/manual/en/pdo.construct.php
To Run a Query: http://www.php.net/manual/en/pdo.prepare.php

@sid8 ;

If you’d like a tutorial approach, check out the latest postings from PHP Master: http://phpmaster.com/avoid-the-original-mysql-extension-2/

You would connect as follows:

mysql_connect(servername,username,password);

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…

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

<?php
// Create connection
$con=mysqli_connect("example.com","peter","abc123","my_db");

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