Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

How to nullify empty strings before inserting to database

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
dzikipsiur
Posts: 2
Joined: Wed Jul 08, 2020 8:21 am

How to nullify empty strings before inserting to database

Unread post by dzikipsiur »

First of all I would like to say hello to everyone on this board as it is my first post.
I have got no background in coding and have got basic knowledge on databases but using nuBuilder I am able to set up frontend the way it is working as I designed it to.
It is a fantastic building environment and would like to say big thank you to the makers.
So far I have managed to do all I wanted just by reading tutorials or posts on this forum until now.
Because I would like to use MySQL CONCAT_WS function to skip NULL values while creating VIEWS for nuBuilder Reports fetching all necessary data from, I have got to the point I simply do not know how to manage my little problem to step further.
I would like to know how to change and where to change nuBuilder PHP procedure globally so instead of an empty string it would insert or update record column with NULL allways and everywhere.
I have seen a post regarding doing so for the DATE data type, but mostly what I want to do it for are text input fields.
I would like to kindly ask to point me in the right direction. I know that there can be triggers created in MySQL engine or NULLIF or conditionals put into use on the MySQL sever side but I would like it to be simply changed at the data source.
Any help appreciated.
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: How to nullify empty strings before inserting to databas

Unread post by kev1n »

Hi,

You could simply modify my fix that sets null for dates and make it more generic to set a NULL value regardless of the column type.

Replace

Code: Select all

if (in_array($type, array('date','datetime','timestamp','year')) && $v == '') {
With

Code: Select all

if ($v == '') {
https://github.com/smalos/nuBuilder4-Bu ... e_types.md
dzikipsiur
Posts: 2
Joined: Wed Jul 08, 2020 8:21 am

Re: How to nullify empty strings before inserting to databas

Unread post by dzikipsiur »

Hi kev1n ,

That worked absolutely the way I imagined it. Amazing!
Thank you very much.
Post Reply