best to have security implemented closest as possible to the data (...) in the database it is ideal.
Why? What? Where? How?
No, the idea that you want to safeguard data has nothing to do with the data layer (e.g. database) in a layered application. In the vast majority of cases that would a terribly bad thing to do.
The idea that you want to safeguard the data is the reasoning where you place the safeguards where the data is kept and processed in each layer of the application (including the database layer if the given data to be safeguarded lies there). If any layer of your application that can perform data requests is compromised then it will bypass the safeguards in the lower layers.
For a simple example: if you have an application where the database access is protected with a password and the application layer stores and reuses that password on connections, then compromising your application layer is all it takes.
A scenario where the idea that safeguards shall be close to the database makes some sense is an application layer that can process encrypted data. For example, where the data is stored encrypted in the database and operations that use this data are performed externally (e.g. in an HSM).