MySQL - Connection MYSQL
- MySQL Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- Drop MySQL Database
- Selecting MySQL Database
- MySQL - Data Types
- Create MySQL Tables
- Drop MySQL Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - WHERE Clause
- MySQL - UPDATE Query
- MySQL - DELETE Query
- MySQL - LIKE Clause
- MySQL - Sorting Results
- Using MySQl Joins
- MySQL - Regexps
- MySQL - Transactions
- MySQL - ALTER Command
- MySQL - INDEXES
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- Using MySQL Sequences
- MySQL - Handling Duplicates
- MySQL - and SQL Injection
- MySQL - Database Export
MySQL - Connection
MySQL Connection Using PHP Script
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.
Example
Try the following example to connect to a MySQL server −
<html> <head> <title>Connecting MySQL Server</title> </head> <body> <?php $dbhost = 'localhost:3306'; //HOST NAME: localhost, PORT NUMBER: 3306 $dbuser = 'guest'; //USERNAME $dbpass = 'guest123'; //PASSWORD $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($conn); ?> </body> </html>