警告:include():在第3行的/ bluehost parth / index.php中打开包含(part_path ='。:/ opt / php70 / lib / php')的'parth'失败

时间:2017-09-06 01:52:02

标签: php

我将我的网站和数据库上传到cPanel bluehost当我通过下面的代码连接数据库时显示错误:

警告:include():在/ bluehost parth / index.php中打开包含(part_path ='。:/ opt / php70 / lib / php')的'parth'失败 第3行

所以所有开发者都帮我解决了这个错误...

数据库配置

<?php

    /*
    * All database connection variables
    */

        $host="localhost";
        $username="root";
        $password="";
        $dbname="db_name";

        $connection=mysql_pconnect($host,$username,$password) or die("connection to the server fail".mysql_error());
        mysql_select_db($dbname, $connection) or die("could not open db:$dbname");

        function db_connect()
        {
            if(!$connection)
            {
                return false;
            }
            if(!mysql_select_db($dbname, $connection))
            {
                return false;
            }

            return  $connection;
        }

        function login($user,$pass)
        {
            db_connect();           

            $result = mysql_query("SELECT * FROM user WHERE username = '".$user."' AND password = '".$pass."'");

            $num_rows = mysql_num_rows($result);

            if($num_rows < 1)   return false;

            mysql_free_result($result);
            return true;
        }
            mysql_query("SET CHARACTER SET 'utf8'");
            mysql_query("SET SESSION collation_connection ='utf8_general_ci'"); 
        ?>

include connection db 

        <?php

包含连接数据库

<?php

    /*
    * I upload my site and database in to cPanel bluehost When me connection database by code below it show error:
    */
            //error_reporting(E_ERROR|E_PARSE);
            include 'atsschool/db_function.php';
            if(empty($_GET['p']))
            {
            $_GET['p']='home';
            }
            if(empty($_GET['page']))
            {
                $_GET['page']='1';
            }
            if(empty($_GET['l']))
            {
                $_GET['l']='english';
            }

        ?>

1 个答案:

答案 0 :(得分:0)

修改
使用下面的代码替换连接脚本中的代码并将其另存为config.php:

<?php
class DBController {
    private $host = "localhost";
    private $user = "DBUSERNAME"; //Replace with your own db username
    private $password = "DBPASSWORD"; //Replace with your own db password
    private $database = "DBNAME"; //Replace with your own db name

    function __construct() {
        $conn = $this->connectDB();
        if(!empty($conn)) {
            $this->selectDB($conn);
        }
    }

    function connectDB() {
        $conn = mysql_connect($this->host,$this->user,$this->password);
        return $conn;
    }

    function selectDB($conn) {
        mysql_select_db($this->database,$conn);
    }

    function runQuery($query) {
        $result = mysql_query($query);
        while($row=mysql_fetch_assoc($result)) {
            $resultset[] = $row;
        }       
        if(!empty($resultset))
            return $resultset;
    }

    function numRows($query) {
        $result  = mysql_query($query);
        $rowcount = mysql_num_rows($result);
        return $rowcount;   
    }
}
?>

然后在您的其他脚本中,您将包含config.php,如下所示:

<?php require_once("folder_where_config.php_is_located/config.php"); ?>
<?php
    if(empty($_GET['p'])) {
        $_GET['p']='home';
    }
    if(empty($_GET['page'])) {
        $_GET['page']='1';
    }
    if(empty($_GET['l'])) {
        $_GET['l']='english';
    }
?>

我建议您尝试使用类似这样的内容进行登录,当然您可以根据自己的喜好对其进行修改,请记住,您实际上并不想使用下面的代码,因为 mysql已被弃用

 <?php
    require_once("config.php");
    $db_handle = new DBController();


    if(!empty($_POST['username']) && ($_POST['password'])) {
        $result = mysql_query("SELECT count(*) FROM users WHERE Username=BINARY'".$_POST['username']."' AND password=BINARY'".$_POST['password']."'"); //You would use BINARY to make sure that the values match word for word, letter by letter, etc
        $row = mysql_fetch_row($result);
        $user_count = $row[0];
        if($user_count<1) {
            echo "error";
        } else {
        //place login function here
        }
    }
?>