gpt4 book ai didi

php - 无法回显数据库项目

转载 作者:行者123 更新时间:2023-11-29 22:14:11 25 4
gpt4 key购买 nike

我试图在 php 中回显一些数据库项目,但似乎没有任何结果。所需的初始化 php 调用存储所有配置的 database.php,如下所示。我做错了什么?

SQL语句:

<?php
require_once("includes/initialize.php");

$userName = $_POST["name"];
$userEmail = $_POST["email"];

$sqlName = "SELECT name FROM individual";
$sqlEmail = "SELECT email FROM individual";

if ($sqlEmail == $userEmail || $sqlName == $userName){

$message = "Hi " + $userName + "this is your new password.";

echo $message;

}

?>

数据库配置位于另一个名为database.php的php文件中。

数据库.php:

<?php

require_once ("config.php");

class MySQLDatabase {

private $connection;

function __construct() {
$this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME) or die
("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
$db_select = mysqli_select_db($this->connection, DB_NAME);
}

public function close_connection() {
if (isset($this->connection)) {
mysqli_close($this->connnection);
unset($this->connection);
}
}

public function query($sql) {
$result = mysqli_query($this->connection, $sql);
$this->confirm_query($result);
return $result;
}

private function confirm_query($result) {
if (!$result) {
die("Database query failed.");
}
}

public function escape_value($string) {

$escaped_string = mysqli_real_escape_string($this->connection, $string);
return $escaped_string;
}

public function fetch_array($id){
if (mysqli_fetch_array($id)) {
return true;
}
}
}

$database = new MySQLDatabase();
$db = & $database;
?>

最佳答案

您没有运行查询.. ..或获取其结果..

$sqlEmail = "SELECT email FROM individual";

$query = $db->query($sqlEmail);

$user = $db->fetch_array($query);

var_dumpr($user);

希望这有帮助..

关于php - 无法回显数据库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31355738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com