PHP MySQL Connect

From CoderLearner
Jump to: navigation, search

PHP MySQL Connect

Connect to the MySQL Server.

Syntax

  • HOST: Host to connect to
  • USER: User name
  • PASS: Password
$connection = mysql_connect(HOST, USER, PASS);

Example 1

<?php

define('HOST', 'localhost');
define('USER', 'user2000');
define('PASS', 'password2000');


$connection = mysql_connect(HOST, USER, PASS);

if (!$connection) {
	die("can not connect to the server!");
}
else {
	echo 'connected and ready to use';
}
mysql_close($connection);
?> 

Output

connected and ready to use