我在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();
我這樣做,似乎mysqlnd可用.. –