Search Posts

How to make MySQL strict on types

how to – How to make MySQL strict on types

Here’s the scenario, we are building a web application in Laravel, and assigned a route as follows:

Route::get('/sample/{client}', '[email protected]')->name('SampleNaming');

The method SampleMethod, reads from the client variable and displays data about the client in the page.

if we go to http://localhost/appurl/sample/1 for example, it displays data about client id 1. The trick is that if we go to http://localhost/appurl/sample/1abc , it will still display the data for client id 1.

Tried the query in MySQL,

select * from clients where ID = '1abc'

It gave me the result for Client ID 1, turns out that MySQL checks the provided string and searches for the integer part in it and fetches the rows accordingly.

Surely, we can escape this in PHP / Laravel however my question is, is there a way to make MySQL strict on such scenarios?

Source: Stackoverflow

Leave a Reply

Your email address will not be published. Required fields are marked *