相关疑难解决方法(0)

如何为MySQL Datetime列设置默认值?

如何为MySQL Datetime列设置默认值?

在SQL Server中它是getdate().什么是MySQL的等价物?如果这是一个因素,我正在使用MySQL 5.x.

mysql datetime

851
推荐指数
19
解决办法
121万
查看次数

自动创建日期 - annoation - Codeigniter 2和Doctrine 2

我正在使用Doctrine 2和Codeigniter 2,我想Doctrine自动生成表格中给定字段中插入的当前日期.

课程文件:

<?php 
namespace models;

/**
 * @Entity
 * @Table(name="workers")
 */
class Workers {
    /**
     * @Id
     * @Column(type="integer", nullable=false)
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @Column(type="string", length=255, unique=true, nullable=false)
     */
    protected $email;

    /**
     * @var datetime $created_on
     * 
     * @gedmo:Timestampable(on="create")
     * @Column(type="datetime")
     */
    protected $created_on;


    /** @PrePersist */
    function onPrePersist()
    {
        $this->created_on = date('Y-m-d H:i:s');
    }

    /* Setters & Getters */
    public function setEmail($email){ $this->email = $email; }
    public function getEmail(){ return $this->email; }
}
Run Code Online (Sandbox Code Playgroud)

插入方法: …

datetime automation doctrine annotations codeigniter

4
推荐指数
2
解决办法
5512
查看次数