Sujet : Re: VMS x86-64 database server
De : arne (at) *nospam* vajhoej.dk (Arne Vajhøj)
Groupes : comp.os.vmsDate : 11. Jul 2025, 00:57:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <104pk1c$13i9u$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
User-Agent : Mozilla Thunderbird
On 7/9/2025 10:24 PM, Arne Vajhøj wrote:
PHP give you the choice of which you want (for mysqli and pdo mysql
and many other).
$ type err1.php
<?php
$con = mysqli_connect('arnepc5', 'arne', 'hemmeligt', 'test');
mysqli_report(MYSQLI_REPORT_OFF);
$stmt = mysqli_prepare($con, 'SELECT the data needed');
if(!$stmt) {
echo mysqli_error($con) . "\r\n";
goto closecon;
}
// whatever
closestmt: mysqli_stmt_close($stmt);
closecon: mysqli_close($con);
?>
$ php err1.php
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'needed' at line 1
$ type err2.php
<?php
$con = mysqli_connect('arnepc5', 'arne', 'hemmeligt', 'test');
mysqli_report(MYSQLI_REPORT_ALL);
try {
$stmt = mysqli_prepare($con, 'SELECT the data needed');
// whatever
mysqli_stmt_close($stmt);
mysqli_close($con);
} catch (mysqli_sql_exception $ex) {
echo $ex->getMessage() . "\r\n";
mysqli_close($con);
}
?>
$ php err2.php
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'needed' at line 1
Default in recent PHP versions is exceptions.
If someone want the same using PDO.
(and yes - everybody should use PDO instead of mysqli!)
$ type err3.php
<?php
$con = new PDO('mysql:host=arnepc5;dbname=test', 'arne', 'hemmeligt');
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$stmt = $con->prepare('SELECT the data needed');
if(!$stmt) {
echo $con->errorInfo()[2] . "\r\n";
goto finish;
}
if(!$stmt->execute()) {
echo $stmt->errorInfo()[2] . "\r\n";
goto finish;
}
// whatever
finish:
?>
$ php err3.php
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use ne
ar 'needed' at line 1
$ type err4.php
<?php
$con = new PDO('mysql:host=arnepc5;dbname=test', 'arne', 'hemmeligt');
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$stmt = $con->prepare('SELECT the data needed');
$stmt->execute();
// whatever
} catch (PDOException $ex) {
echo $ex->getMessage() . "\r\n";
}
?>
$ php err4.php
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'needed' at line 1
Arne