Sujet : Re: VMS x86-64 database server
De : arne (at) *nospam* vajhoej.dk (Arne Vajhøj)
Groupes : comp.os.vmsDate : 10. Jul 2025, 03:24:50
Autres entêtes
Organisation : SunSITE.dk - Supporting Open source
Message-ID : <686f2472$0$686$14726298@news.sunsite.dk>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
User-Agent : Mozilla Thunderbird
On 7/9/2025 9:21 PM, Lawrence D'Oliveiro wrote:
On Wed, 9 Jul 2025 19:51:30 -0400, Arne Vajhøj wrote:
error_reporting(E_ERROR) is not need to get SQL errors - it is to avoid
getting warnings about mysql extension being obsolete.
I think you need
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
in order to get error exceptions raised about incorrect MySQL. Sensible
languages would do this by default.
There are fundamentally two different ways of handling errors:
* return status
* exception
Different languages use different approaches. C use return status.
Java use exception.
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.
I prefer exceptions over return status, but not everybody agrees.
PHP provide a way to use return status for those that prefer that.
Some must prefer it that way. There are also newer languages
being created without exceptions.
I would say that in general high level languages do exceptions
while low level languages don't do exceptions.
PHP is a high level language, but while PHP in recent years
has been very inspired by Java, then in the beginning it was
very inspired by C. It got some baggage - a common example
is all the strxxx functions.
Arne