Home  >  Article  >  Backend Development  >  Does php have a mysql_connect function?

Does php have a mysql_connect function?

WBOY
WBOYOriginal
2022-03-14 15:02:251880browse

There is the "mysql_connect()" function in PHP. This function is used to open a non-persistent MySQL connection. If successful, it will return a MySQL connection identifier. If it fails, it will return false. The syntax is "mysql_connect(server, username, password, newlink, clientflag)".

Does php have a mysql_connect function?

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

Does PHP have a mysql_connect function?

The mysql_connect() function opens a non-persistent MySQL connection.

Syntax

mysql_connect(server,user,pwd,newlink,clientflag)
  • server Optional. Specifies the server to connect to. Can include the port number, such as "hostname:port", or the path to the local socket, such as ":/path/to/socket" for localhost. If the PHP directive mysql.default_host is not defined (the default case), the default value is 'localhost:3306'.

  • user Optional. username. The default value is the username of the server process owner.

  • pwd Optional. password. The default value is an empty password.

  • newlink Optional. If mysql_connect() is called a second time with the same parameters, a new connection will not be established, but the ID of the already opened connection will be returned. The parameter new_link changes this behavior and makes mysql_connect() always open a new connection, even when mysql_connect() has been called previously with the same parameters.

  • clientflag Optional. The client_flags parameter can be a combination of the following constants:

MYSQL_CLIENT_SSL - Use SSL encryption

MYSQL_CLIENT_COMPRESS - Use compression protocol

MYSQL_CLIENT_IGNORE_SPACE - Allow after the function name Interval

MYSQL_CLIENT_INTERACTIVE - Allows interaction timeout inactivity time before closing the connection

Return value

If successful, a MySQL connection identifier is returned, otherwise FALSE is returned.

Examples are as follows:

<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
  {
  die(&#39;Could not connect: &#39; . mysql_error());
  }// 一些代码...mysql_close($con);
?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Does php have a mysql_connect function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn