| Server IP : 93.86.61.54 / Your IP : 216.73.216.60 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/projects/tempcontrol/debug/ |
Upload File : |
<?php
// test_db_simple.php
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "Testing database connection...\n";
$host = 'localhost';
$db = 'temperature_db';
$user = 'temperature_user';
$pass = 'secure_password_123';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
echo "✅ Connected to database successfully!\n";
// Test SELECT
$stmt = $pdo->query("SELECT COUNT(*) as count FROM temperature_logs");
$result = $stmt->fetch();
echo "✅ Records in table: " . $result['count'] . "\n";
// Test INSERT
$sql = "INSERT INTO temperature_logs (sensor_id, temperature, humidity, pressure, heating_command) VALUES (?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute(['test-sensor', 22.5, 45.0, 1013.25, 'off']);
echo "✅ Insert successful! Last ID: " . $pdo->lastInsertId() . "\n";
} catch (PDOException $e) {
echo "❌ Connection failed: " . $e->getMessage() . "\n";
echo "Error Code: " . $e->getCode() . "\n";
}
?>