简体   繁体   中英

Inserting a timestamp into a MySQL table

I have an array I'm inserting into a table:

$leadValues = array();
$leadValues[ 'LEADCOMM' ] = getVariable('LEADCOMM');
$leadValues[ 'CCID' ] = getVariable('CCID');
$leadValues[ 'QTR' ] = getVariable('QTR');
$leadValues[ 'CLK' ] = getVariable('CLK');
$leadValues[ 'DCK' ] = getVariable('DCK');
$leadValues[ 'QS_PRODUCT' ] = getVariable('QS_PRODUCT');
$leadValues[ 'PROP_ST' ] = getVariable('PROP_ST');
$leadValues[ 'QS_PROP_DESC' ] = getVariable('QS_PROP_DESC');
$leadValues[ 'QS_CRED_GRADE' ] = getVariable('QS_CRED_GRADE');
$leadValues[ 'EST_VAL' ] = getVariable('EST_VAL');
$leadValues[ 'BAL_ONE' ] = getVariable('BAL_ONE');
$leadValues[ 'QS_FHA_BANK_FORECLOSURE' ] = getVariable('QS_FHA_BANK_FORECLOSURE');
$leadValues[ 'QS_VA_STATUS' ] = getVariable('QS_VA_STATUS');
$leadValues[ 'FNAME' ] = getVariable('FNAME');
$leadValues[ 'LNAME' ] = getVariable('LNAME');
$leadValues[ 'ADDRESS' ] = getVariable('ADDRESS');
$leadValues[ 'CITY' ] = getVariable('CITY');
$leadValues[ 'PROP_ZIP' ] = getVariable('PROP_ZIP');
$leadValues[ 'EMAIL' ] = getVariable('EMAIL');
$leadValues[ 'PRI_PHONE_1' ] = getVariable('PRI_PHONE_1');
$leadValues[ 'PRI_PHONE_2' ] = getVariable('PRI_PHONE_2');
$leadValues[ 'PRI_PHONE_3' ] = getVariable('PRI_PHONE_3');
$leadValues[ 'PPCID '] = getVariable('PPCID');
$leadValues[ 'CID' ] = getVariable('CID');

I want to add a final item to the array that will insert a time stamp into the table. Would something like this work?

$leadValues[ 'TS' ] = $date->format( 'd/m/Y H:i:s' );

you may use time() function. it returns current unix timestamp

$leadValues[ 'TS' ] = time();

Ideally you'd modify the table for your 'timestamp' field to be a TIMESTAMP datatype. It will do its own automatic initialization and update, taking this additional step away from PHP.

See http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM