1

I have this simple chunk of code that updates the user's last login with the current timestamp. If last_login is set to NULL and then I perform an UPDATE query it will work, however it won't if last_login already has a value.

Here's my code:

PHP:

$time = time();
$user_id = $active_user->id;
DB::query('UPDATE `users` SET `last_login` = ? WHERE `id` = ?;', array($time, $user_id));
mightyspaj3
  • 471
  • 1
  • 8
  • 22
  • Do you have any error ? – D4V1D Mar 31 '15 at 05:44
  • No errors are showing, it's just not updating – mightyspaj3 Mar 31 '15 at 05:44
  • 1
    I think `query` is only for select. See [here](http://stackoverflow.com/questions/18323065/update-query-with-pdo-and-mysql) how do you use PDO with update. – Jens Mar 31 '15 at 05:44
  • I have a custom DB query object, I use this all the time and it works fine. – mightyspaj3 Mar 31 '15 at 05:46
  • 1
    Show the code of your custom DB query. – Jens Mar 31 '15 at 05:51
  • 1
    It's impossible to diagnose without the code in your static `query` method. All I can say for now is to ensure you're developing with `error_reporting = E_ALL` and `display_errors = On` in your `php.ini` file as well as setting PDO attributes `$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)` – Phil Mar 31 '15 at 06:00
  • Also, got any triggers in your database? – Phil Mar 31 '15 at 06:02
  • try updating with a hard coded timestamp first to ensure if the update code really fires. – MansoorShiraz Mar 31 '15 at 06:04
  • Your query is not going to work with your current configuration, see this question. http://stackoverflow.com/questions/11172777/make-pdoquery-static – EternalHour Mar 31 '15 at 07:26

0 Answers0