简体   繁体   中英

What is the best way to insert Null Data Mysql

I'm looking on my project to create an entry on my database wuth PHP and MySQL. I've created an class "Order" and iside this class I have a function to create a new entry in my Database.

On my code I want to reuse this function, but hte fact is, when i create the entry I haven't all the Datas (Some Datas are inserted later in the process). So my question is the next one. What is the best to manage it ?

Should I generate some data as NULL ? (that's my fort idea) Like that ?

 $unknow = NULL;
 $end_date = date('d/m/Y', strtotime("+1 month"));
 $user = checkConnected($bdd);
 Order::create($bdd, $new_full_modele_devis_path, $unknow, $end_date, 0, $user->getId(), $unknow, $entreprise->getId());

or should I rework my finction to ignore empty datas ?

Thank you for your answers.

Let database fill the NULL values. Make those fields nullable in database which you want to insert later.

When you make your database structure you can set default values of your fields. In your case if a field may not be filled in you can set the default value as NULL meaning you don't need to touch that field in your code until you want to save a value to it.

It is not a good practice to save the null values. Instead you set the default values so that when there is null value then it would save default value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM