/home/u764571690/domains/savitrfoundation.com/public_html/scholar
Edit: /home/u764571690/domains/savitrfoundation.com/public_html/scholar/db.php (7908B)
false,
// Error handling
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
// Fetch mode
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
// Disable emulated prepares for better security and performance
PDO::ATTR_EMULATE_PREPARES => false,
// Set connection timeout (reduced for faster failure)
PDO::ATTR_TIMEOUT => 3,
// ✅ Enable buffered queries for better performance
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
]
);
// ✅ Set MySQL timezone to India (important line)
$pdo->exec("SET time_zone = '+05:30'");
// ✅ Optimize MySQL settings for better performance
$pdo->exec("SET SESSION sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");
// ✅ PERFORMANCE: Optimize for high concurrency (5000+ users)
$pdo->exec("SET SESSION wait_timeout = 300"); // 5 minutes
$pdo->exec("SET SESSION interactive_timeout = 300");
$pdo->exec("SET SESSION max_join_size = 18446744073709551615"); // Allow large joins
// ✅ PERFORMANCE: Additional MySQL optimizations for high concurrency
// Note: query_cache_type can't be set at session level if globally disabled
// $pdo->exec("SET SESSION query_cache_type = 1"); // Removed - requires global config
try {
$pdo->exec("SET SESSION innodb_lock_wait_timeout = 50"); // Faster lock timeout
} catch (PDOException $e) {
// Ignore if not supported (older MySQL versions)
}
} catch(PDOException $e) {
error_log("Database connection failed: " . $e->getMessage());
die("Database connection failed: " . $e->getMessage());
}
date_default_timezone_set('Asia/Kolkata');
function getDBConnection() {
global $pdo;
return $pdo;
}
function testConnection() {
try {
global $pdo;
$stmt = $pdo->query("SELECT 1");
return true;
} catch(PDOException $e) {
return false;
}
}
define('DB_HOST', 'localhost');
define('DB_NAME', 'u764571690_scholarship');
define('DB_USER', 'u764571690_scholarship');
define('DB_PASS', 'Ojaspunj@6264');
class DatabaseHelper {
public static function sanitizeInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
public static function validateEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
public static function validatePhone($phone) {
return preg_match('/^[0-9]{10}$/', $phone);
}
public static function validateAadhar($aadhar) {
return preg_match('/^[0-9]{12}$/', $aadhar);
}
public static function getStudentById($id) {
global $pdo;
try {
$stmt = $pdo->prepare("SELECT * FROM students WHERE id = ?");
$stmt->execute([$id]);
return $stmt->fetch();
} catch(PDOException $e) {
error_log("Error fetching student: " . $e->getMessage());
return false;
}
}
public static function getAllStudents() {
global $pdo;
try {
$stmt = $pdo->query("SELECT * FROM students ORDER BY created_at DESC");
return $stmt->fetchAll();
} catch(PDOException $e) {
error_log("Error fetching students: " . $e->getMessage());
return false;
}
}
public static function getApplicationsByStatus($status) {
global $pdo;
try {
$stmt = $pdo->prepare("
SELECT a.*, s.name, s.email, s.phone
FROM applications a
JOIN students s ON a.student_id = s.id
WHERE a.status = ?
ORDER BY a.applied_at DESC
");
$stmt->execute([$status]);
return $stmt->fetchAll();
} catch(PDOException $e) {
error_log("Error fetching applications: " . $e->getMessage());
return false;
}
}
}
class SimpleCache {
private static $cacheDir = __DIR__ . '/../cache';
private static $defaultTTL = 300; // 5 minutes default
public static function init() {
if (!file_exists(self::$cacheDir)) {
@mkdir(self::$cacheDir, 0755, true);
}
}
public static function get($key) {
self::init();
$file = self::$cacheDir . '/' . md5($key) . '.cache';
if (!file_exists($file)) {
return false;
}
$data = unserialize(file_get_contents($file));
// Check if expired
if (time() > $data['expires']) {
@unlink($file);
return false;
}
return $data['value'];
}
public static function set($key, $value, $ttl = null) {
self::init();
$ttl = $ttl ?? self::$defaultTTL;
$file = self::$cacheDir . '/' . md5($key) . '.cache';
$data = [
'value' => $value,
'expires' => time() + $ttl,
'created' => time()
];
return @file_put_contents($file, serialize($data)) !== false;
}
public static function delete($key) {
self::init();
$file = self::$cacheDir . '/' . md5($key) . '.cache';
return @unlink($file);
}
public static function clear() {
self::init();
$files = glob(self::$cacheDir . '/*.cache');
foreach ($files as $file) {
@unlink($file);
}
}
public static function cleanExpired() {
self::init();
$files = glob(self::$cacheDir . '/*.cache');
$cleaned = 0;
foreach ($files as $file) {
$data = unserialize(file_get_contents($file));
if (time() > $data['expires']) {
@unlink($file);
$cleaned++;
}
}
return $cleaned;
}
}
if (rand(1, 100) === 1) {
SimpleCache::cleanExpired();
}
// ✅ Error reporting (disable in production for security)
// Set environment variable 'APP_ENV=production' to disable error display
$isProduction = (getenv('APP_ENV') === 'production' ||
(isset($_SERVER['APP_ENV']) && $_SERVER['APP_ENV'] === 'production') ||
(strpos($_SERVER['HTTP_HOST'] ?? '', 'localhost') === false &&
strpos($_SERVER['HTTP_HOST'] ?? '', '127.0.0.1') === false));
if ($isProduction) {
// Production: Log errors but don't display them
error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/../logs/php_errors.log');
// Create logs directory if it doesn't exist
$logDir = __DIR__ . '/../logs';
if (!file_exists($logDir)) {
@mkdir($logDir, 0755, true);
}
} else {
// Development: Show errors for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
}
?>