php函数 mysql_connect 的详细用法及实例_php mysql_connect 与mysql_pconnect函数与实例教程...

php教程 mysql教程_connect 与mysql_pconnect函数与实例教程

mysql_connect

mysql_connect($this->root,$this->user,$this->pass)

/*

mysql_connect ,单个反问用户不会频繁的调用数据库教程,没必要保持连接,而且mysql的连接数也是有限制的, 使用 及时访问比较频繁,也最好使用mysql_connect,这样使用的过的资源可以立刻释放,否则,容易造成资源耗

*/

mysql_pconnect

/*

mysql_pconnect() 函数打开一个到 MySQL 服务器的持久连接

*/

$con = mysql_pconnect("localhost","mysql_user","mysql_pwd");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

class testLinkMysql{

public $conn;

public $root='localhost';

public $user='root';//'loupan';

public $pass='root';//'loupandsffds';

public $db='dbname';

public $charset='gbk';

public $links='c'; //标题

function __construct() {

if( !$this->conn )

{

$this->connect();

}

}

function __destruct() {

if( $this->conn )

{

$this->close();

}

}

function MysqlConnect()

{

try{

if( 'p' == $this->links )

{

$this->conn = mysql_pconnect($this->root,$this->user,$this->pass) or die(mysql_error());

}

else

{

$this->conn = mysql_connect($this->root,$this->user,$this->pass) or die( mysql_error());

}

mysql_select_db($this->db,$this->conn);

mysql_query("set Names '$this->charset'");

}catch (Exception $e){

echo '数据库连接失败,请联系相关人员!';

exit;

}

}

function close()

{

mysql_close($this->links);

}

}

/*

总结:

mysql_pconnect() 和 mysql_connect() 非常相似,但有两个主要区别:

当连接的时候本函数将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的(持久)连接,如果找到,则返回此连接标识而不打开新连接。

其次,当脚本执行完毕后到 SQL 服务器的连接不会被关闭,此连接将保持打开以备以后使用(mysql_close() 不会关闭由 mysql_pconnect() 建立的连接)。

本站原创教程转载注明来源http://www.111cn.net/phper/php.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值