We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Mysql save date()

Hi @all,

why can i not save date()? Everything is saved, but not the date()!

public function saveSuccessLogin($user){
    $successLogin = new SuccessLogins();
    $successLogin->usersId = $user->id;
    $successLogin->ipAddress = $this->request->getClientAddress();
    $successLogin->userAgent = $this->request->getUserAgent();
    $successLogin->userAttempted = date("Y-d-m H:i:s");
    if (!$successLogin->save()) {
        $messages = $successLogin->getMessages();
        throw new Exception($messages[0]);
    }
}

Mysql structure table:

userAttempted -> datetime 0000-00-00 00:00:00

Rgds

Stefan



58.4k

Hey man

The date mysql use format Y-m-d H:i:s so you try change

    $successLogin->userAttempted = date("Y-m-d H:i:s");


59.9k

Hey Thien,

hope you are fine :-)

Sorry but it won't work, i also tried varchar, text or char. The other fields will be inserted.

This is my Model, it is vökuro Standard, except the userAttempted

    <?php
    namespace Vokuro\Models;

    use Phalcon\Mvc\Model;

    /**
     * SuccessLogins
     * This model registers successfull logins registered users have made
     */
    class SuccessLogins extends Model
    {

        /**
         *
         * @var integer
         */
        public $id;

        /**
         *
         * @var integer
         */
        public $usersId;

        /**
         *
         * @var string
         */
        public $ipAddress;

        /**
         *
         * @var string
         */
        public $userAgent;

        public $userAttempted;

        public function initialize()
        {
            $this->belongsTo('usersId', 'Vokuro\Models\Users', 'id', array(
                'alias' => 'user'
            ));
        }
    }

Rgds

Stefan



85.5k

model cache perhaps ?



59.9k
edited Nov '15

Hi Izo,

i cleard the volt cache. There are anther caches: acl, metaData, swift and volt, which contains data.txt.

Maybe this?!

Rgds

Stefan



85.5k

can you trycleaning your cache in DEV inviorment

this is how i decrale my caches


$this->di->set('modelsCache', function(){

            $frontCache = new FrontendData(
                array(
                    "lifetime" => 186400
                )
            );

            $cache = new Redis($frontCache, array(
                'host' => '127.0.0.1',
                'port' => 6379,
                "statsKey" => '_PHCM'
            ));

            if (APPLICATION_ENV === 'development'){
                $cache->flush();
            }

            return $cache;
        }, true);

Do you have a query log available?



59.9k

Hi quasipickle,

what i have is a meta-vokuro_models_successlogins-success_logins.php in my metaData directory

That is the code:

<?php return array (
  0 => 
  array (
    0 => 'id',
    1 => 'usersId',
    2 => 'ipAddress',
    3 => 'userAgent',
  ),
  1 => 
  array (
    0 => 'id',
  ),
  2 => 
  array (
    0 => 'usersId',
    1 => 'ipAddress',
    2 => 'userAgent',
  ),
  3 => 
  array (
    0 => 'id',
    1 => 'usersId',
    2 => 'ipAddress',
    3 => 'userAgent',
  ),
  4 => 
  array (
    'id' => 0,
    'usersId' => 0,
    'ipAddress' => 5,
    'userAgent' => 2,
  ),
  5 => 
  array (
    'id' => true,
    'usersId' => true,
  ),
  8 => 'id',
  9 => 
  array (
    'id' => 1,
    'usersId' => 1,
    'ipAddress' => 2,
    'userAgent' => 2,
  ),
  10 => 
  array (
  ),
  11 => 
  array (
  ),
  12 => 
  array (
  ),
  13 => 
  array (
  ),
); 

Thx in advance

Stefan



59.9k
Accepted
answer

Hi @all,

i did it.

I deleted all the files of the metaData directory and logged in again. Now the date is written into the table.

Thx to all for help

Rgds

Stefan