【问题标题】:How do I create a php.ini file for GoDaddy shared hosting?如何为 GoDaddy 共享主机创建 php.ini 文件?
【发布时间】:2016-06-26 01:05:19
【问题描述】:

在 PHP 中运行某个方法时出现错误。我调查了一下,似乎我需要 mysqlnd 驱动程序。我知道我必须在 php.ini 文件中进行配置,但由于我与 GoDaddy 共享主机,我无权访问 ini 文件。我打电话给 GoDaddy,他们基本上说,你必须创建自己的。我的问题是,我的案例中的ini文件放在哪里?我需要创建一个php.ini 文件还是一个php5.ini。另外,我将如何在文件中写入设置,我从未使用过 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();

【问题讨论】:

    标签: php apache ini


    【解决方案1】:

    php.ini 的位置取决于您拥有的托管帐户类型。根据 GoDaddy:

    更多详情请见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 docroot 中,在你的浏览器中加载文件的 URL,它会告诉你有哪些 PHP 模块可用。

    如果mysqlnd 实际可用,则可以使用本地php.ini 文件配置一些(不是很多)选项。见这里:http://php.net/manual/en/mysqlnd.config.php

    【讨论】:

    • 如何在我的 GoDaddy VPS 服务器中安装 oAuth? @大卫
    【解决方案2】:

    你可以像这样创建 php.ini 文件:

    1. 如果您是 Windows 用户,请启动一个新的空白记事本文件,写一些东西 并“另存为”php.ini

    2. 如果你是 mac 用户,启动 text-edit 写一些东西去“格式”菜单然后选择“制作纯文本”然后保存为 'php.ini

    典型内容如下所示:

    display_errors = 关闭 error_reporting = 0

    在您的情况下,您可能需要根据确切的错误消息设置路径。 您收到的错误信息是什么?

    mysql.default_socket="/your/path/to/mysql.sock"

    保存更改并上传到您的网站根目录,例如public_html

    替换:

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

    与:

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

    【讨论】:

    • 我在日志文件中得到的错误是:PHP 致命错误:在第 33 行的 /home/user/public_html/include/DB_Functions.php 中调用未定义的方法 mysqli_stmt::get_result() .
    • 您能否发布您正在使用的 Db_Functions.php 代码,或者至少发布此文件中第 33 行及其附近的完整方法。 mysqli_stmt::get_result() 仅适用于 PHP v5.3.0 或更高版本。
    • 另外,您是否通过查看 phpinfo 文件验证了 MySQL Native Driver (mysqlnd) 驱动程序已安装在您的 Godaddy 主机上?
    • 是的,我将编辑问题以提供 DB_Functions.php 代码。我之前看到过这个问题,发现需要 PHP v5.3.0 并且我正在运行 v5.4.0。我确实运行了 phpinfo 文件,我注意到它说 mysqlnd 可用。
    • 我几天前更新了我的答案 - 如果这对你有用,请告诉我。如果可能的话,也请向上/向下投票。祝你好运!
    【解决方案3】:

    听起来您正在收到“致命错误:调用未定义的方法 mysqli_stmt::get_result()”

    如果是这样,您必须确保您确实有“mysqlnd启用, 最简单的方法是通过构建一个 php 信息页面 enter link description here 它应该是这样的:enter image description here

    来自 Godaddy Cpanel,确保您使用的是最新的 php 版本。 从那里“php Extensions”确保启用“-mysqlnd & -nd_mysql & -nd_mysqli & -nd_pdo_mysql”

    这样您将摆脱致命错误并且您的脚本应该可以正常工作!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 2018-05-15
      • 2012-05-31
      • 2017-04-16
      • 1970-01-01
      相关资源
      最近更新 更多