0

I'm trying to do an update in MySQL from PHP with CodeIgniter, but, how can I insert a now() method? I mean, I'm using an array to insert my information, but, how can I insert the date? This is an example of my array:

$data = array(
   'name'     => $inputName,
   'lastname' => $inputLast,
   'DOBirth'  => now()
);
Quill
  • 2,729
  • 1
  • 33
  • 44

1 Answers1

1

NOW() is part of MySQL, not PHP, so you need to put into the query.

Try this way, which is how you handle it using PDO. This should work:

$stmt = $pdoDb->prepare('INSERT INTO tablename (name, lastname, dobirth) VALUES (:name, :lastname, NOW())');
// either bind each parameter explicitly 
$stmt->bindParam(':name', $name); 
$stmt->bindParam(':lastname', $lastname);
$stmt->execute();

source: Datetime NOW PHP mysql (+ PDO variant)

Community
  • 1
  • 1
manuelbcd
  • 3,106
  • 1
  • 26
  • 39