1

对不起,因为我在 PHP 方面很糟糕

因此,我发现自己非常愚蠢地被阻止了,因为我无法理解,或者我必须将我的信息放在我的数据库文件“class_DbConnect.php”中的连接中

如果文件看起来像这样:

https://github.com/manifestinteractive/easyapns/blob/master/src/php/classes/class_DbConnect.php ...

所以我试图通过观看“演示”的视频自己解决它,但它已经过时了。从演示中获取的 php 文件不同,至少不同到足以让我烦恼!

我确信这很简单:我有 4 个信息(主机、用户名、密码和数据库名称),但我不知道在文件中的何处设置它们......我知道它在这个文件中但不知道在哪里。

其余的,我们稍后会看到。我已经创建了必要的数据库,我还必须了解证书的方式,如何恢复等等......但是现在,我希望已经完成了 php 部分......

我将在这里发布不同的发现和行动......我很确定它对其他人有用。

4

2 回答 2

2

您不要将信息放入文件中,而是在声明类时添加它们

解释

该类包含

/**
* Constructor. Initializes a database connection and selects our database.
* @param string $host       The host to wchich to connect.
* @param string $username   The name of the user used to login to the database.
* @param string $password   The password of the user to login to the database.
* @param string $database   The name of the database to which to connect.
*/
function __construct($host, $username, $password, $database)
{
    $this->DB_HOST     = $host;
    $this->DB_USERNAME = $username;
    $this->DB_PASSWORD = $password;
    $this->DB_DATABASE = $database;
}

你在 PHP 代码中需要的是这样的

$db = new DbConnect("localhost","username","password","database");

这是一个bad practice尝试直接在类中硬编码值,如果您需要连接到多个hostdatabase

乔·伯内特

作为一个初学者,当 MySQL 作为出色的 `mysqli' 扩展时,你不需要这样的类,它也是面向对象的并且非常快。

用法与您没有的类似,但不需要任何额外的内容,包括任何类

例子

$db = new mysqli("localhost","username","password","database");

有关更多信息和示例,请参见http://www.php.net/manual/en/mysqli.construct.php

于 2012-04-12T20:48:27.893 回答
0

我会说那是我见过的最长的 MySQL 连接脚本,但是给你...

function __construct($host, $username, $password, $database)
    {
        $this->DB_HOST     = "HostName";
        $this->DB_USERNAME = "username";
        $this->DB_PASSWORD = "password";
        $this->DB_DATABASE = "database";
    }

在您的代码中找到该函数并编辑其内容。把你的信息放在“”里面。

于 2012-04-12T20:42:04.873 回答