[英]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. 我正在寻找项目,以在数据库中使用PHP和MySQL创建一个条目。 I've created an class "Order" and iside this class I have a function to create a new entry in my Database.
我创建了一个“ Order”类,并且在该类的基础上,我具有一个在数据库中创建新条目的功能。
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 ? 我应该将某些数据生成为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. 让数据库填充NULL值。 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. 在您的情况下,如果可能未填写字段,则可以将默认值设置为
NULL
这意味着您无需在代码中触摸该字段,除非您想向其中保存一个值。
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.
而是设置默认值,以便当存在空值时它将保存默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.