23 lines
767 B
PHP
23 lines
767 B
PHP
<?php
|
|
// Database configuration
|
|
define('DB_HOST', '127.0.0.1');
|
|
define('DB_NAME', 'real_estate');
|
|
define('DB_USER', 'app_user');
|
|
define('DB_PASS', 'Secure@Password123');
|
|
|
|
/**
|
|
* Establishes a database connection using PDO.
|
|
* @return PDO A PDO database connection object.
|
|
*/
|
|
function db_connect() {
|
|
try {
|
|
$pdoconn = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
|
|
$pdoconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
return $pdoconn;
|
|
} catch (PDOException $e) {
|
|
// In a real app, you'd log this error and show a generic message
|
|
die("Database connection failed: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// You can now include this file and call db_connect() to get a database connection.
|