2016-03-10 45 views
-2

我在PHP中運行某種方法時出現錯誤。我看着它,似乎我需要mysqlnd驅動程序。我知道我必須在php.ini文件中進行配置,但由於我與GoDaddy共享了託管,因此我無法訪問ini文件。我打電話給GoDaddy,他們基本上說,你必須創建自己的。我的問題是,ini文件放在我的情況下在哪裏?我是否需要創建一個php.ini文件或php5.ini。另外,如何將這些設置寫入文件中,我從未使用過ini文件,而且我也不知道它的外觀。如何爲GoDaddy共享主機創建php.ini文件?

DB_Functions.php代碼:

<?php 

class DB_Functions { 

    private $con; 

    function __construct() { 
     require_once 'DB_Connect.php'; 

     $db = new DB_Connect(); 
     $this->con = $db->connect(); 
    } 

    function __destruct() { 

    } 

    public function storeUser($name, $email, $password) { 
     $uuid = uniqid('', true); 
     $hash = $this->hashSSHA($password); 
     $encrypted_password = $hash['encrypted']; 
     $salt = $hash['salt']; 

     $stmt = $this->con->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())"); 
     $stmt->bind_param('sssss', $uuid, $name, $email, $encrypted_password, $salt); 
     $result = $stmt->execute(); 
     $stmt->close(); 

     if ($result) { 
      $stmt = $this->con->prepare("SELECT * FROM users WHERE email = ?"); 
      $stmt->bind_param('s', $email); 
      $stmt->execute(); 
      $user = $stmt->get_result()->fetch_assoc(); 
      $stmt->close(); 

      return $user; 
     } else { 
      return false; 
     } 
    } 

    public function getUserByEmailAndPassword($email, $password) { 
     $stmt = $this->con->prepare("SELECT * FROM users WHERE email = ?"); 

     $stmt->bind_param('s', $email); 

     if ($stmt->execute()) { 
      $user = $stmt->get_result()->fetch_assoc(); 
      $stmt->close(); 

      $salt = $user['salt']; 
      $encrypted_password = $user['encrypted_password']; 
      $hash = $this->checkhashSSHA($salt, $password); 

      if ($encrypted_password == $hash) { 
       return $user; 
      } 
     } else { 
      return NULL; 
     } 
    } 

    public function getUserByNameAndPassword($name, $password) { 
     $stmt = $this->con->prepare("SELECT * FROM users WHERE name = ?"); 

     $stmt->bind_param('s', $name); 

     if ($stmt->execute()) { 
      $user = $stmt->get_result()->fetch_assoc(); 
      $stmt->close(); 

      $salt = $user['salt']; 
      $encrypted_password = $user['encrypted_password']; 
      $hash = $this->checkhashSSHA($salt, $password); 

      if ($encrypted_password == $hash) { 
       return $user; 
      } 
     } else { 
      return NULL; 
     } 
    } 

    public function doesUserEmailExist($email) { 
     $stmt = $this->con->prepare("SELECT email FROM users WHERE email = ?"); 

     $stmt->bind_param('s', $email); 

     $stmt->execute(); 

     $stmt->store_result(); 

     if ($stmt->num_rows > 0) { 
      $stmt->close(); 
      return true; 
     } else { 
      $stmt->close(); 
      return false; 
     } 
    } 

    public function doesUserNameExist($name) { 
     $stmt = $this->con->prepare("SELECT name FROM users WHERE name = ?"); 

     $stmt->bind_param('s', $name); 

     $stmt->execute(); 

     $stmt->store_result(); 

     if ($stmt->num_rows > 0) { 
      $stmt->close(); 
      return true; 
     } else { 
      $stmt->close(); 
      return false; 
     } 
    } 

    public function hashSSHA($password) { 
     $salt = sha1(rand()); 
     $salt = substr($salt, 0, 10); 
     $encrypted = base64_encode(sha1($password . $salt, true) . $salt); 
     $hash = array('salt' => $salt, 'encrypted' => $encrypted); 
     return $hash; 
    } 

    public function checkhashSSHA($salt, $password) { 
     $hash = base64_encode(sha1($password . $salt, true) . $salt); 

     return $hash; 
    } 

} 

?> 

我在使用相同的兩行代碼得到錯誤。

$user = $stmt->get_result()->fetch_assoc(); 

回答

0

php.ini的位置將取決於您擁有的託管帳戶的類型。據GoDaddy的:

enter image description here

詳情請參閱https://www.godaddy.com/help/what-filename-does-my-php-initialization-file-need-to-use-8913

但是,如果mysqlnd尚未由GoDaddy編譯和安裝,您很可能無法通過擁有本地php.ini文件來解決任何問題。你可以看到通過創建一個小的PHP文件(例如test.php)安裝了哪些模塊包含此:

<?php phpinfo(); ?> 

假如把它放在你的HTML文檔根目錄,加載該文件的URL在瀏覽器中,它會告訴你什麼PHP模塊可用。

如果mysqlnd實際上可用,則可以使用本地php.ini文件配置幾個(不是很多)選項。在這裏看到:http://php.net/manual/en/mysqlnd.config.php

+0

我這樣做,似乎mysqlnd可用.. –

0

您可以創建php.ini文件,像這樣:

  1. 如果你是一個Windows用戶火了一個新的空白記事本文件寫的東西 和「另存爲」 PHP。 INI

  2. ,如果你是一個Mac用戶,火起來的文本編輯寫的東西去「格式」菜單,選擇「製作純文本」,然後保存爲「php.ini中

典型內容是這樣的:

的display_errors =關閉 的error_reporting = 0

在你的情況,你可能需要設置取決於確切的錯誤消息的路徑。 你得到的錯誤信息是什麼?

mysql.default_socket = 「/你/路徑/要/的mysql.sock」

更改保存並上傳到網站根如的public_html

替換:

$user = $stmt->get_result()->fetch_assoc(); 

有了:

$stmt->bind_result(); 
$user = $stmt->fetch(); 
+0

我在我的日誌文件中得到的錯誤是:PHP致命錯誤:調用未定義的方法mysqli_stmt :: get_result()在/ home/user/public_html /在第33行包含/ DB_Functions.php。 –

+0

您可以發佈您正在使用的Db_Functions.php代碼,或者至少從該文件的第33行開始發佈完整的代碼。 mysqli_stmt :: get_result()僅在PHP v5.3.0或更高版本中可用。 – Sean

+0

另外,您是否已通過查看phpinfo文件來驗證您的Godaddy主機上是否安裝了MySQL Native Driver(mysqlnd)驅動程序? – Sean

0

這聽起來像你得到 「致命錯誤:調用未定義的方法mysqli_stmt :: get_result()」

如果是這樣,你必須確保你有「mysqlnd啓用, 最簡單的方法知道,通過建立一個PHP信息頁面enter link description here它應該是這樣的:enter image description here

從Godaddy Cpanel,請確保您使用的是最新的PHP版本。 從那裏「PHP擴展」請確保啓用「-mysqlnd & -nd_mysql & -nd_mysqli & -nd_pdo_mysql」

這樣你將擺脫的致命錯誤,你的腳本應該正常工作!