OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :
 

Connecting to MySql

By admin (2009-02-27. 8243 views.)
Describe how to connect to a MySql instance

The standard function for connecting to a MySql instance or server is the function call mysql_connect(). The function takes several arguments:


<?php

$handle 
mysql_connect($server, [$username$password$newlink$clientflag]);

?>


Where:

$handle is the returned connection made. If this value is empty an error occurred which can be retrieved using mysql_err()

$server is the address of the MySql instance. If you are running on a desktop this would typically be "localhost". In a shared/production environment this will typically be the ip address or dns name of the database server.

$username is the username to use as far as access control to the database. You may have several different 'user's within the database, each with their own set of access rights to the database. This field is optional and defaults to the database owner.

$password is the password associated with the username provided. This field is optional and defaults to "". You will hardly every see a default password used.

$newlink is an optional flag that tells PHP to attempt to use an existing connection with the same credentials, if it is available. Again, you will hardly ever see this in use in a production environment.

$clienflag contains optional settings concerning the connection. Not normally used, but possible:
MYSQL_CLIENT_SSL - Use SSL encryption
MYSQL_CLIENT_COMPRESS - Use compression protocol
MYSQL_CLIENT_IGNORE_SPACE - Allow space after function names
MYSQL_CLIENT_INTERACTIVE - Allow interactive timeout seconds of inactivity before closing the connection

By default the connection will automatically be closed when PHP finishes processing the script for the page in use.

You can place an '@' sign in front of the call to avoid errors being thrown into your page generation. This is a commonly used technique.
 

 
   Print this page

Top Sponsor

Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting

Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005