简体   繁体   中英

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. 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. And you are stating

$query->executy();

which should be

$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();

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