[英]Inserting dateTime into mysql won't work
I am trying to insert a date (joinedate of user) i use this code: 我试图插入一个日期(用户的加入),我使用此代码:
$dateTime = new DateTime();
$date = $dateTime->format('Y-m-d H:i:s');
$query = $this->_pdo->prepare('INSERT INTO web_users VALUES(:joinedate)');
$query->bindParam(':joinedate', $date);
$query->execute();
This is in pdo and when i execute this it will just set null in the database. 这是在pdo中,当我执行此操作时,它将在数据库中设置为null。 The database column is a datetime so it should work.
数据库列是一个日期时间,因此它应该可以工作。
Hope someone can help me! 希望可以有人帮帮我!
As @Marc B stated, you need to specify the column unless you have only one column. 如@Marc B所述,除非只有一列,否则需要指定列。 And you are stating
你说
$query->executy();
which should be 应该是
$query->execute(); $ query-> execute();
And you have a typo here: 您在这里有错别字:
:joinedate is not like in bind_param :joindedate
Code: 码:
$query = $this->_pdo->prepare('INSERT INTO web_users (column) VALUES(:joinedate)');
//^are you sure this is right?
$query->bindParam(':joinedate', $date);
$query->execute();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.