-1

如果有人能告诉我如何为 mysqli 替换/修复它,我将不胜感激。这是两个示例,因此我可以从中学习并修复所需的所有内容。

样品 1:

include dirname(__FILE__) . '/database.php';
mysql_select_db(databasename, mysql_connect(server, user, pass));

$q_settings = mysql_query("SELECT * FROM settings");

$settings = array();
while ($setting_one = mysql_fetch_array($q_settings)) {
    $settings[$setting_one["name"]] = $setting_one["value"];
}

样本 2:

$one_blog = mysql_fetch_array(mysql_query("SELECT * FROM blog WHERE id = '" . mysql_real_escape_string($_GET["id"]) . "' LIMIT 1"));

感谢您提供任何提示和示例。我已经尝试了一些来自 php.net 用户评论的示例,但在某些情况下我失败了。这就是我所做的。

$db_select = mysqli_connect(server, user, pass, databasename) or die("Error " . mysqli_error($db_select));

$db_query = "SELECT * FROM settings";
$db_result = $db_select->query($db_query) or die("Error in the consult..." . mysqli_error($db_select));

$settings = array();
while ($setting_one = mysqli_fetch_array($db_result)) {
    $settings[$setting_one["name"]] = $setting_one["value"];
}
4

2 回答 2

0

对于您的第一个样本:

$mysqli = mysqli_connect("server", "user", "password", "database");
$q_settings = $mysqli->query("SELECT * FROM settings");

$settings = array();

while($row = $q_settings->fetch_assoc()){
    $settings[$row["name"]] = $row["value"];
}
于 2013-11-05T13:02:15.313 回答
-1

我一遍又一遍地尝试,我相信这是我的第二个示例的正确方法。

$one_blog = mysqli_fetch_array($mysqli->query("SELECT * FROM blog WHERE id = '" . $mysqli->real_escape_string($_GET["id"]) . "' LIMIT 1"));

感谢韦恩提供您的第一个样品。它真的很有帮助。

于 2013-11-05T14:01:46.773 回答