mysql_pconnect无法正常工作

时间:2014-09-08 06:19:23

标签: php mysql database-connection

我已经创建了一个php连接文件作为explorecalirfornia.php内容,如下所示。

#FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_explorecalirfornia = "localhost";
$database_explorecalirfornia = "explorecalirfornia";
$username_explorecalirfornia = "root";
$password_explorecalirfornia = "";
$explorecalirfornia = mysql_pconnect($hostname_explorecalirfornia, $username_explorecalirfornia, $password_explorecalirfornia) or trigger_error(mysql_error(),E_USER_ERROR);

我已使用命令

在我的页面中包含此php文件
<?php require_once('Connections/explorecalifornia.php'); ?> 

当我使用本地主机测试php代码时出现以下错误。

img

请帮我完成我的教程。

2 个答案:

答案 0 :(得分:1)

  Either @mysql_pconnect($hostname_explorecalirfornia, $username_explorecalirfornia, $password_explorecalirfornia) or trigger_error(mysql_error(),E_USER_ERROR);  //@ infront of mysql_pconnect or use below written code

    $mysqli = new mysqli(HOST, USERNAME, PASSWORD, DBNAME);
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
     }

答案 1 :(得分:0)

mysql_ *functions已弃用,将来不再使用。请改用mysqli_* functionsPDO。结识The PHP Manual.

$explorecalirfornia = new mysqli($hostname_explorecalirfornia, $username_explorecalirfornia, $password_explorecalirfornia);

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}