On 27/02/2021 18:10, Kamil Tekiela wrote:

    Select * From products Where product_id = 'hello world'

    If product_id is a column of type int, then the database will raise an
    error about incompatible types.


No, this query would produce a warning. I am unaware of an SQL mode that would turn this warning into an error.


Right, I forgot we were talking about MySQL, which has the same "ignore and carry on" tradition as PHP; in other DBMSes, that would be an error:

PostgreSQL:

> ERROR: invalid input syntax for type integer: "hello world"
> LINE 1: Select * From products Where product_id = 'hello world';

Microsoft SQL Server:

> Msg 245 Level 16 State 1 Line 1
> Conversion failed when converting the varchar value 'hello world' to data type int.


However, the main point of the example was to show that an error could go unnoticed, and actually have no immediate negative effects, such that replacing it with an exception makes things worse.



Examples, that would truly be effected are something like this:

$stmt = $mysqli->query('INSERT INTO tableA (uniqueColumn) VALUE("repeated value")');
if (1062 === $mysqli->errno) {
    echo "Can't add this value because it already exists!";
}

If the developer didn't silence the errors then the user will see a generic error instead of the specific one.


Precisely, and this is what people are concerned about: if someone is writing code from scratch, exception-by-default is a good thing; but if they have existing error handling, by-passing that handling by throwing an exception is not.


Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to