I'm after this answer, and this is my code:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$SERVER = "192.168.0.50";
$DATABASE = "MYDB";
const USERNAME = "username";
const PASSWORD = "password";
try {
$db = new PDO("odbc:MYDB", USERNAME, PASSWORD,
array(
PDO::ATTR_TIMEOUT => 1, // in seconds
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
} catch (PDOException $e) {
echo '<div class="alert alert-danger" role="alert">';
echo "Connection to database failed:" . PHP_EOL . $e->getMessage();
echo '</div>';
}
The remote database is not reachable, but despite the timeout setting it takes about 18 seconds to timeout.
I'm using PHP 8.2.4 on Ubuntu 22.04 and ODBC Driver 18 for SQL Server.
source https://stackoverflow.com/questions/76806333/php-pdo-odbc-connection-timeout-is-not-honored
No comments:
Post a Comment