Create a connection of MySQL through PHP

IN this article I am going to explain connection in MySQL.
  • 1792

Create a Connection to a MySQL Database

You must have to create connect with MySQL Database before the access data from the database. And for create connection in PHP mysql_connect() function used.

Syntax of MySQL database connection

mysql_connect(servername,username,password);


Parameters in Mysql connect method

There are following three parameters in mysql_connect method:

Parameter Description
Servername Optional. Specifies the server to connect to. Default value is "localhost:3306"
username Optional. Specifies the username to log in with. Default value is the name of the user that owns the server process
password Optional. Specifies the password to log in with. Default is ""

Example of creating MySQL connection

<?php
$con = mysql_connect("localhost","gupta","password@123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// other code

mysql_close($con); //closing a connection
?>

You may also want to read these related articles click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.