Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

mysql connect function syntax tag tutorial 2013 Donate at flattr Flattr this





Alert! Connect with 10,000 Chating Online. Join Now

Php mysql connect () function

Write your php code

 
<?php ?>

Php Result


Your code below



(PHP 3, PHP 4 , PHP 5)

mysql_connect -- Open a connection to a MySQL Server

Syntax

resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] )

Opens or reuses a connection to a MySQL server. The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close().

Parameters

server

The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost.

If the PHP directive mysql.default_host is undefined (default), then the default value is 'localhost:3306'

username

The username. Default value is the name of the user that owns the server process.

password

The password. Default value is an empty password.

new_link

If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters.

client_flags

The client_flags parameter can be a combination of the following constants: MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE or MYSQL_CLIENT_INTERACTIVE.

Return Values

Returns a MySQL link identifier on success, or FALSE on failure.

ChangeLog

VersionSyntax
4.3.0 Added the client_flags parameter.
4.2.0 Added the new_link parameter.
3.0.10 Added support for ":/path/to/socket" with server.
3.0.0 Added support for ":port" with server.

Examples

Example 1. mysql_connect() example

<?php
$link
= mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!
$link) {
    die(
'Could not connect: ' . mysql_error());
}
echo
'Connected successfully';
mysql_close($link);
?>

Notes

Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as mysql.default_host in your PHP configuration and leave the server field blank.

Note: The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close().

Note: You can suppress the error message on failure by prepending a @ to the function name.

Php mysql connect Function syntax tag

mysql connect php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php mysql connect syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online