-
stlake2011
Junior Member
-
Posts: 31
Threads: 15
Joined: Jan 2020
Reputation:
1
Hi guys,
Quick question, minor problem (I think)!
I am trying to update a 'DateTime' column in MariaDB/MySQL using the builder class but I keep getting this error:
Call to undefined function App\Models\now()
I tried setting the update column using the following methods:
Method 1:
PHP Code: $UpdateData = [ 'title' => $title, 'slug' => $slug, 'updated' => NOW(), 'post' => $post ]; $builder->where('slug',$slug);
$builder->update($UpdateData);
Method 2:
PHP Code: $builder->set('updated=NOW()'); $builder->where('slug',$slug);
$builder->update($UpdateData);
Method 3:
PHP Code: $builder->set('updated',NOW()); $builder->where('slug',$slug);
$builder->update($UpdateData);
Is there something I am missing here? Or is it impossible to work with Maria/MySQL's internal functions using the Builder Class?
No biggie if its impossible, as I can always resort to PHP Date/Time functions and have PHP do the work instead of MariaDB doing it.
So this is more of a curiosity question as well as a serious one.
-
InsiteFX
Super Moderator
-
Posts: 6,514
Threads: 324
Joined: Oct 2014
Reputation:
239
Because CodeIgniter no longer has the now() method.
Here I created a helper to do it, make sure to place the methods into a help file.
PHP Code: / -----------------------------------------------------------------------
/** * now () method */ if ( ! function_exists('now')) { function now() { // uses the default timezone. return date_create('now')->format('Y-m-d H:i:s'); } }
// -----------------------------------------------------------------------
/** * nowTimeZone () method */ if ( ! function_exists('nowTimeZone')) { function nowTimeZone($timeZone) { // $timeZone format 'America/New_York' return date_create('now', timezone_open($timeZone))->format('Y-m-d H:i:s'); } }
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
stlake2011
Junior Member
-
Posts: 31
Threads: 15
Joined: Jan 2020
Reputation:
1
(09-09-2020, 05:26 AM)InsiteFX Wrote: Because CodeIgniter no longer has the now() method.
Here I created a helper to do it, make sure to place the methods into a help file.
PHP Code: / -----------------------------------------------------------------------
/** * now () method */ if ( ! function_exists('now')) { function now() { // uses the default timezone. return date_create('now')->format('Y-m-d H:i:s'); } }
// -----------------------------------------------------------------------
/** * nowTimeZone () method */ if ( ! function_exists('nowTimeZone')) { function nowTimeZone($timeZone) { // $timeZone format 'America/New_York' return date_create('now', timezone_open($timeZone))->format('Y-m-d H:i:s'); } }
Thanks man for the helper, I figured there was something along those lines going on, but just wasn't sure what it was.
-
nfaiz
Member
-
Posts: 53
Threads: 7
Joined: Apr 2015
Reputation:
3
(09-08-2020, 03:40 PM)stlake2011 Wrote: Hi guys,
Quick question, minor problem (I think)!
I am trying to update a 'DateTime' column in MariaDB/MySQL using the builder class but I keep getting this error:
Call to undefined function App\Models\now()
I tried setting the update column using the following methods:
Method 1:
PHP Code: $UpdateData = [ 'title' => $title, 'slug' => $slug, 'updated' => NOW(), 'post' => $post ]; $builder->where('slug',$slug);
$builder->update($UpdateData);
Method 2:
PHP Code: $builder->set('updated=NOW()'); $builder->where('slug',$slug);
$builder->update($UpdateData);
Method 3:
PHP Code: $builder->set('updated',NOW()); $builder->where('slug',$slug);
$builder->update($UpdateData);
Is there something I am missing here? Or is it impossible to work with Maria/MySQL's internal functions using the Builder Class?
No biggie if its impossible, as I can always resort to PHP Date/Time functions and have PHP do the work instead of MariaDB doing it.
So this is more of a curiosity question as well as a serious one.
How about
PHP Code: $builder->set('updated', 'NOW()', false); $builder->where('slug',$slug);
$builder->update($UpdateData);
|