我最近有一个问题让我发疯,每当我试图查询数据库时,总是得到一个空的结果!
请帮助,我在这里为任何更多的信息或细节。
这是数据库类:
final class database
{
private const DB_HOST = 'localhost';
private const DB_NAME = 'branches';
private const DB_CHARSET = 'utf8';
private const DB_USER = 'public_user';
private const DB_PASS = '1y37*V9ddGd@';
public const EMAIL_TO = 'someone@gmail.com';
public static function database_connect()
{
// setting DSN (Data Source Name)
$dsn = 'mysql:host=' . self::DB_HOST . ';' . 'charset=' . self::DB_CHARSET;
try {
// creating a PDO (PHP Data Object) instance
$pdo = new PDO($dsn, self::DB_USER, self::DB_PASS);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
} catch (PDOException $e) {
if (DEBUG === true) {
echo "<pre><br><var>";
print_r('An error has occured during database connection initiation Big Boss: <br> ' . $e);
echo "</var></pre><br>";
} else {
$headers = "From: admin@company.com" . "\r\n";
$headers .= "Reply-To: No One" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
if (mail(self::EMAIL_TO, 'An error has occured', $e, $headers)) {
echo 'المعذرة حدث خطاء فادح! لقد تم إرسال الخطاء إلى مطور الموقع لمعالجتة.';
} else {
echo 'الرجاء التواصل مع مدير موقع شركة الجزيرة إخوان للصرافة على الإيميل التالي: <br>
someone@gmail.com';
}
}
}
}
private function __clone() {}
}
我就是这样从索引页查询数据库的:
<?php
$connection = Database::database_connect();
$select_database = "use branches";
Database::database_query($connection, $select_database);
$get_all_branches_query = "SELECT * FROM jazz_branches_ar WHERE branch_status = 1";
$query_results = Database::database_query($connection, $get_all_branches_query);
foreach ($query_results as $branch) {
echo "<tr>";
echo "<td>", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_fax'])))) , "</td>";
echo "<td><a class=\"inline-links\" href=\"tel:", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_tel'])))), "\">", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_tel'])))) ,"</a></td>";
echo "<td>", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_address'])))), "</td>";
echo "<td>", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_city'])))), "</td>";
echo "</tr>";
}
?>
笔记:
我正在使用与戈达迪共享主机。
我在下面添加的旧代码曾经工作得很好。
这是我以前的数据库类,您可以看到它忽略了各种安全措施:
class Database
{
private static $_db_host = 'mysql:host=localhost;charset=utf8';
private static $_db_user = 'jazz_god';
private static $_db_pass = 'LcaQVNH3qz6Cksow';
public static function database_connect()
{
return $db_info = new PDO(Database::$_db_host, Database::$_db_user, Database::$_db_pass);
}
public static function database_query($db_connection, $query)
{
$statment = $db_connection->prepare($query);
$statment->execute();
$result = $statment->fetchAll(PDO::FETCH_ASSOC);
return $result;
}
}
这是用来查询数据库的代码:
<?php
$connection = Database::database_connect();
$select_database = $connection->prepare('use jazz_agents_branches');
$select_database->execute();
$get_all_branches_query = "SELECT * FROM jazz_branches_ar WHERE branch_status = 1";
$query_results = Database::database_query($connection, $get_all_branches_query);
foreach ($query_results as $branch) {
echo "<tr>";
echo "<td>", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_fax'])))) , "</td>";
echo "<td><a class=\"inline-links\" href=\"tel:", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_tel'])))), "\">", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_tel'])))) ,"</a></td>";
echo "<td>", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_address'])))), "</td>";
echo "<td>", htmlspecialchars(strip_tags(stripslashes(trim($branch['branch_city'])))), "</td>";
echo "</tr>";
}
?>
尽管我将我的应用程序置于危险之中,但我决定在下面列出我使用的库和php版本:
1条答案
按热度按时间yizd12fk1#
把这个:
在尝试中:
您的代码必须是:
类的电子邮件错误将电子邮件更改为public您无法访问类的私有属性: