报错:Fatal error: Uncaught Error: Call to undefined function mysql_connect() in 和php网站打开一片空白【解决】

 

mysql_connect()这个函数不再使用

 

 不要修改php.ini文件,改成mysqli_connect()就可以了

全局替换后

报错:Warning: mysqli_error() expects exactly 1 parameter, 0 given in

    $con = mysqli_connect( $dbhost, $dbuser, $dbpass );
    if ( !$con ) {
        die( '数据库链接出错,请检查账号密码及地址是否正确: ' . mysqli_error() );
    }

之前开了数据库端口,重新改为3306后:

 

原代码:

    $con = mysql_connect( $dbhost, $dbuser, $dbpass );
    if ( !$con ) {
        die( '数据库链接出错,请检查账号密码及地址是否正确: ' . mysql_error() );
    }

    $result = mysql_query('show databases;') or die ( mysql_error() );;
    While($row = mysql_fetch_assoc($result)){       
        $data[] = $row['Database'];
    }
    unset($result, $row);
    if (in_array(strtolower($dbname), $data)){
        mysql_close();
        echo "<script>if(!alert('數據庫已存在')){window.history.back(-1);}</script>";
        exit();
    }

    mysql_query( "CREATE DATABASE $dbname", $con ) or die ( mysql_error() );

修改为


    $con = mysqli_connect( $dbhost, $dbuser, $dbpass );
    if ( !$con ) {
        die( '数据库链接出错,请检查账号密码及地址是否正确: ' . mysqli_error() );
    }

    $result = mysqli_query($con,'show databases;') or die ( mysqli_error($con) );;
    While($row = mysqli_fetch_assoc($result)){
        $data[] = $row['Database'];
    }
    unset($result, $row);
    if (in_array(strtolower($dbname), $data)){
        mysqli_close();
        echo "<script>if(!alert('數據庫已存在')){window.history.back(-1);}</script>";
        exit();
    }

    mysqli_query( $con,"CREATE DATABASE $dbname" ) or die ( mysqli_error($con) );

数据库连接成功

 

 

经过已上安装成功后,点击确认,然后页面一片空白:

 

检查配置文件,猜测是配置文件配置不正确导致 ,

参考:https://help.aliyun.com/knowledge_detail/36451.html

 

先查看配置文件,

<?php

error_reporting(0);

if (!file_exists($_SERVER["DOCUMENT_ROOT"] . '/sys/install.lock')) {
    header("Location: /install/install.php");
    exit;
}

include_once '../sys/lib.php';

$host = "localhost";
$username = "root";
$password = "root";
$database = "vauditdemo";

$conn = mysql_connect($host, $username, $password);
mysql_query('set names utf8', $conn);
mysql_select_db($database, $conn) or die(mysql_error());
if (!$conn) {
    die('Could not connect: ' . mysql_error());
    exit;
}

session_start();

?>

修改为:

<?php

error_reporting(0);

if (!file_exists($_SERVER["DOCUMENT_ROOT"] . '/sys/install.lock')) {
header("Location: /install/install.php");
exit;
}

include_once '../sys/lib.php';

$host = "localhost";
$username = "root";
$password = "root";
$database = "vauditdemo";

$conn = mysqli_connect($host, $username, $password);
mysqli_query('set names utf8', $conn);
mysqli_select_db($conn,$database) or die(mysqli_error());
if (!$conn) {
die('Could not connect: ' . mysqli_error());
exit;
}

session_start();

?>

打开成功:

posted on 2019-12-20 11:18  Ra7ing安全实验室  阅读(26267)  评论(0编辑  收藏  举报

导航