Friday, September 10th, 2010

PHP MYSQL mysql_connect – Connect to a MySQL server

The mysql_connect function is used to connect to a MySQL Server.

Syntax:

resource mysql_connect (string $Hostname, string $Username, string $Password);

Arguments:
$Hostname
The hostname is the URL or the IP address of the MySQL server. If the PHP script is running on the same system as the MySQL server, “localhost” can be used as a hostname.
$Username
The username must be a valid user of the MySQL server.
$Password
The password must be the MySQL password for the username.

Return value:
If the connection is successful, the return value will be the handle of the connection.
If the connection fails, the return value wil be a boolean false.

Example code:

<?php
 
$UserName = 'abc';
$Password = '8sj27s';
$DbHandle = mysql_connect ('localhost', $UserName, $Password);
if (!$DbHandle) {
  die 'No database connection could be established.';
}
 
?>
Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Tags: ,

Readers Comments (0)




Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.


Latest Additions

Popular User Submitted Links

1


Hosted & Optimized JS Libraries – Cached Commons

1


Multi-File Uploader & Resizer – Agile Uploader

1


Open source online notebook-to-do-list manager

1


3 tier app design in silverlight using azure & RIA services

1


Polymaps – A JS Library For Image & Vector-Tiled Maps

eXTReMe Tracker