Heim  >  Artikel  >  php教程  >  PHP MySQL入门教程之连接数据库

PHP MySQL入门教程之连接数据库

WBOY
WBOYOriginal
2016-05-25 16:37:37813Durchsuche

在php中连接数据有mysql_connect() 函数或mysql_pconnect()函数来完成,下面我给大家php入门者简单介绍介绍.

常用连接函数mysql_connect()

mysql_connect(servername,username,password);

长连接函数mysql_pconnect()

mysql_pconnect(servername,username,password);

PHP实例代码如下:

<?php 
$con = mysql_connect("localhost","peter","abc123"); 
if (!$con) 
{ 
    die(&#39;Could not connect: &#39; . mysql_error()); 
} 
// some code

说的是mysql_pconnect,怎么能绕开MySQL的设置,影响mysql_pconnect最重要的两个参数就是wait_timeout和interactive_timeout,代码如下:

<?php 
$conn = mysql_pconnect("localhost","root","123456") or die("Can not connect to MySQL"); 
echo "MySQL线程号:". MySQL_thread_id($conn). "<br />"; 
echo "Apache进程号". getmypid();


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