当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > mysql_connect() 函数

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 中的 mysql_connect() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 529 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The mysql_connect() function opens a non-persistent MySQL connection.
mysql_connect()函数的作用是:打开一个到 MySQL 服务器的连接。

This function returns the connection on success, or FALSE and an error on failure. You can hide the error output by adding an '@' in front of the function name.
该函数如果成功执行,将返回这个连接,如果失败,将返回False。当然你也可以在函数名称前面添加一个“@”来隐藏产生的错误。

Syntax
语法

mysql_connect(server,user,pwd,newlink,clientflag)

Parameter
参数
Description
描述
server Optional. Specifies the server to connect to (can also include a port number. e.g. "hostname:port" or a path to a local socket for the localhost). Default value is "localhost:3306"
可选参数。指定需要连接的服务器(他可以包含一个端口号。案例:“hostname:port”,或者一个连接到本地服务器的路径)。默认值为:“localhost:3306”
user Optional. Specifies the username to log in with. Default value is the name of the user that owns the server process
可选参数。指定登陆的用户名。默认的用户名是该服务器拥有者的名字
pwd Optional. Specifies the password to log in with. Default is ""
可选参数。指定登陆的密码。默认值为""
newlink Optional. If a second call is made to mysql_connect() with the same arguments, no new connection will be established; instead, the identifier of the already opened connection will be returned
可选参数。如果你使用相同的自变量对mysql_connect()函数发出第二次请求,那么,它将建立一个新的连接;同样,它将返回已经打开的连接
clientflag Optional. Can be a combination of the following constants:
 可选参数。可以使用的值如下:
  • MYSQL_CLIENT_SSL - Use SSL encryption
    MYSQL_CLIENT_SSL – 使用SSL技术加密
  • MYSQL_CLIENT_COMPRESS - Use compression protocol
    MYSQL_CLIENT_COMPRESS – 使用压缩[compression]协议
  • MYSQL_CLIENT_IGNORE_SPACE - Allow space after function names
    MYSQL_CLIENT_IGNORE_SPACE – 允许在函数名称后面出现空格
  • MYSQL_CLIENT_INTERACTIVE - Allow interactive timeout seconds of inactivity before closing the connection
    MYSQL_CLIENT_INTERACTIVE – 在关闭连接之前,允许对休止状态下的函数设置激活时间


Tips and Notes
提示

Tip: The connection will be closed as soon as the script ends. To close the connection before, use mysql_close().
提示:但脚本程序结束运行后,连接将被关闭;你可以使用mysql_close()函数关闭这个连接。

Tip: To establish a persistent MySQL connection, use mysql_pconnect() instead.
提示:你可以使用mysql_pconnect()函数建立一个持久的MySQL连接。


Example
案例

<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con) { die('Could not connect: ' . mysql_error()); }
// some code
mysql_close($con);
?>

评论 (0) All

登陆 | 还没注册?