2017-09-06 76 views
-1

在/ BlueHost的PARTH/index.php文件上傳我的網站和數據庫到cPanel bluehost當我通過下面的代碼連接數據庫時顯示錯誤:警告:包括():打開失敗 'PARTH' 列入(include_path中= ':/選擇/ php70/lib中/ PHP的')在第3行

Warning:include():在/ bluehost中打開'parth'包含(include_path ='。:/ opt/php70/lib/php')失敗在 線PARTH/index.php的3

因此所有開發者幫助解決我的這個錯誤...

DB配置

<?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 

包括連接DB

<?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'; 
      } 

     ?> 
+0

警告:include():在/home1/hotelkci​​/public_html/atsschool/index.php中打開'atsschool/db_function.php'以包含(include_path ='。:/ opt/php70/lib/php')失敗在第3行 –

+0

我想第二個文件是index.php,在這種情況下,它在與'db_function.php'文件相同的目錄中。你需要引用它作爲剛'包括「db_function.php」;'或者'包括「../ atsschool/db_function.php」;' – mbozwood

回答

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 
     } 
    } 
?> 
+0

是我存放我的數據庫在phpMyAdmin已經 –

+0

@SIENGCHAMPA看到更新後的代碼 – JeanPaul98

+0

是我感謝你,我遵循上面的代碼,但它仍然是錯誤之前。 –

相關問題