Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
MySQL Connection In PHP
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. MySql Tutorials
  3. MySQL Connection In PHP

MySql Tutorial

Basic MySql Tutorials

  • MySql Table Content
  • MySQL Introduction
  • MySQL Constraints
  • MySQL Connection In PHP
  • MySQL Create Database In PHP
  • MySQL Create Table using PHP
  • MySQL Insert Using PHP
  • MySQL Update Using PHP
  • MySQL Delete Using PHP
  • MySQL Select Using PHP
  • MySQL Order By Using PHP
  • MySQL Where Clause Using PHP
  • MySQL Fetch Array Using PHP
  • MySQL Fetch Assoc Using PHP
  • MySQL Fetch Row Using PHP
  • MySQL Fetch Object Using PHP
  • MySQL Basic Queries

Basic MySqli Tutorials

  • MySQLi Connection In PHP
  • MySQLi Create Database In PHP
  • MySQLi Create Table using PHP
  • MySQLi Insert Using PHP
  • MySQLi Update Using PHP
  • MySQLi Delete Using PHP
  • MySQLi Select Using PHP
  • MySQLi Order By Using PHP
  • MySQLi Where Clause Using PHP
  • MySQLi Fetch Array Using PHP
  • MySQLi Fetch Assoc Using PHP
  • MySQLi Fetch Row Using PHP
  • MySQLi Fetch Object Using PHP
  • MySQLi Predefined Function In PHP

MySQL Connection In PHP

PHP provides mysql_connect() function to open a database connection. This function takes five parameters and returns a MySQL link identifier on success or FALSE on failure.

Syntax

//connection 
mysql_connect(server_name,user_name,password,database_name);
Parameter Description
host(Server name) Either a hostname(server name) or an IP address (If you are working on local system then use localhost or 127.0.0.1 )
username The MySQL user name
password The password to log in with
database_name Optional. The database to be used when performing queries

 

Create Connection In MYSQL using PHP:

<?php

// Create connection
$db=mysql_connect("localhost","root","","my_db") or die(mysql_error());

?>

 

Close Connection In MYSQL Using PHP:

<?php
	// Create connection

	$db=mysql_connect("localhost","root","","myDatabaseName") or die(mysql_error());	

	//code to be executed...

	// Close connection	

	mysql_close($db);
   
?>

Note: After work with the database is completed we have to close the connection using mysql_close() function in which the connection to the database is passed.

 

Series: MySql Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
php mysqli connect php mysql select database database connection in php with mysql in xampp mysql_select_db in php php database connection example program database connection in php using wamp server mysql connect command line php mysql query

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.