Heim  >  Artikel  >  Datenbank  >  PHP和MYSQL数据库的链接_MySQL

PHP和MYSQL数据库的链接_MySQL

WBOY
WBOYOriginal
2016-06-01 13:31:31844Durchsuche

bitsCN.com  在MYSQL数据库的众多函数中,用来连接的函数有两个,分别是:MysQL—connect()和MySQL__pconnect()。语法如下:

  int MySQL—connect(string[hostname](:[Port,string[username],string[password])int MySQL__pconnect(string[hostname](:[Port,string[username],string[password])在连接成功后,这两个函数都返回一个连接号;如果失败,则返回一个false值。在参数中,主机名(hostname)中可以包含数据库服务的端口号(port),通常使用默认的端口号。如果什么参数都个填,那么默认的主机名是“localhost”,用户名(username)是数据库管理者,默认为“root”,密码(Password)为空。

  使用MysQL connect()建立连接时,当操作数据库结束后,会自动关闭已建立的连接,除非在此之前,已经强行使用MySQL—close()关闭了连接。而使用MysQL—pconnect()在每次连接时,都会自动检查是否有使用相同主机名、用户名和密码建立的连接,如果有,则直接使用这个连接的连接号。并且,使用MySQL—pconnect()是种稳固持久的连接,这个连接不会因为操作数据库的动作停止而停止。而且也不会被函数MySQL_commect()终止。

  程序示例:

  <?php$connect=MySQL_connect(‘localhost’,‘username’,‘password’);

  echo“$connect”;

  ?>

  程序运行结果为:(1)。这说明,程序已经同数据库连接上了。

 

文章来源:景安网络http://host.zzidc.com/  转载注明

bitsCN.com
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn