I got these errors on my script error log iam using php version 5.3 and this is my code :
// add entry
$sql = "INSERT INTO plugin_reward_ppd_detail (reward_user_id, download_ip, file_id, download_country_group_id, download_date, reward_amount, status)
VALUES (:reward_user_id, :download_ip, :file_id, :download_country_group_id, :download_date, :reward_amount, 'pending')";
$vals = array('reward_user_id' => $file->userId,
'download_ip' => $usersIp,
'file_id' => $file->id,
'download_country_group_id' => $countryGroupId,
**'download_date' => sqlDateTime(),**
'reward_amount' => $rewardAmount);
$db->query($sql, $vals);
}
I got error on this exactly :
'download_date' => sqlDateTime()
if you want add current time on download_date column you can try this one
use DATE(''YYYY-MM-DD HH:MM:SS');
$vals = array('reward_user_id' => $file->userId,
'download_ip' => $usersIp,
'file_id' => $file->id,
'download_country_group_id' => $countryGroupId,
'download_date' =>DATE('YYYY-MM-DD HH:MM:SS'),
'reward_amount' => $rewardAmount);
$db->query($sql, $vals);
}
OR
other wise set download_date MySQL data-type: TIMESTAMP –
Defulat value select : CURRENT_TIMESTAMP
This an advanced version of DATETIME datatype. It has the same format as before. Unlike DATETIME, TIMESTAMP stores the current date and time on the creation of the table and on every update automatically. You do
not need to change its value every time
Related
I'm using datetime picker in Yii2
DateTimePicker::widget([
'name' => 'dp_1',
'options' => [ 'id' => 'time_picker'],
'pluginOptions' => [
'todayHighlight' => true,
]
])
and get value like this:
var date = $("#time_picker").datetimepicker('getDate').getTime()/1000;
but when I select it display duplicate :
I have no idea about this ,please help me
Instead of
var date = $("#time_picker").datetimepicker('getDate').getTime()/1000;
Use
var date = $("#time_picker").val();
Because, First time you used DateTimePicker. It's Ok. While getting the value again for DateTimePicker, You are again initializing it $("#time_picker").datetimepicker...
So, My opinion is to use var date = $("#time_picker").val(); and do all calculations after getting date value.
I have a table I need to pull records from if the row is between certain times. But some of the times are UFN(until further notice). How can I get cakephp to ignore the 'end' time if the end time is a string and not a time? Would it be easier if I force the user to keep the 'end time' blank if they want to display UFN?
Thanks in advance
EDIT:
The project I'm working on is sensitive so I can't post any of the actual code, but here's an example.
$this->Event->find('all', array(
'conditions' => array(
'Event.active_start <' => date('Y-m-d H:i:s', strtotime($date . " +31 minutes")),
'Event.active_stop >' => $date,
'Event.id >' => $id,
),
'order' => 'Event.active_start',
'group' => 'Event.id'
)
);
Event.active_start is always a datetime, but Event.active_stop can be a datetime or a string, usually 'UFN'.
This query is not pulling any rows that are strings.
Make 'Event.active_stop' as DATETIME field, allow to be empty.
Before save check if datetime format, if not unset($string)
After find (callback) if active_stop is empty field, return string 'UFN'
Alright, so i have a huge list (like 500+) of entries in an array that i need to insert into a MySQL database.
I have a loop that populates an array, like this:
$sms_to_insert[] = array(
'text' => $text,
'contact_id' => $contact_id,
'pending' => $status,
'date' => $date,
'user_id' => $this->userId,
'sent' => "1"
);
And then i send it to the database using the built insert_batch() function:
public function add_sms_for_user($id, $sms) {
//$this->db->delete('sms', array("user_id" => $id)); Irrelevant
$this->db->insert_batch('sms', $sms); // <- This!
}
The error message i get is as follows:
Column count doesn't match value count at row 1.
Now, that doesn't make sense at all. The columns are the same as the keys in the array, and the values are the keys value. So, why is it not working?
Any ideas?
user_id turned out to be null in some situations, that's what caused the error.
EDIT: If you replace insert_batch() with a loop that runs insert() on the array keys you will get more clear error messages.
hi im having little trouble at inserting date from drupal to mysql
here the code that i'm trying
.....
$form['kotak']['tgl'] = array(
'#type' => 'date',
'#title' => t('Tanggal'),
);
.....
function awal_form_submit($form,&$form_state){
global $user;
$entry = array(
'tanggal' => $form_state['values']['tgl'],
);
$tabel = 'jp_1';
$return = insert_form($entry,$tabel);
}
.....
function insert_form($entry,$tabel){
$return_value = NULL;
try {
$return_value = db_insert($tabel)
->fields($entry)
->execute();
}
.....
everytime i'm submit, error code like this
db_insert failed. Message = SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1, query= INSERT INTO {jp_1} (tanggal) VALUES (:db_insert_placeholder_0_month, :db_insert_placeholder_0_day, :db_insert_placeholder_0_year)
any suggestion or correction?
From the mysql error it looks like the table you created has required fields (a columns Null property is set to 0, which means that there must be a value for tha column for every row you want to insert)
Check whether there are any columns which have null set to 0.
From your example I can't see what you're trying to achieve, but in many cases it's not necessary to write into db tables manually (using db_insert()) as you can get the same result easier by creating a content type (node type) which handles a lot of functionality for you.
I hope that helps, Martin
i'm finally managed to find the answer, all i need is download "Date" module and activate its "Date API". Here the code
.....
$datex = '2005-1-1';
$format = 'Y-m-d';
$form['kotak']['tgl'] = array(
'#type' => 'date_select',
'#default_value' => $datex,
'#date_format' => $format,
'#date_year_range' => '-10:+30',
'#title' => t('Tanggal'),
);
.....
function awal_form_submit($form,&$form_state){
global $user;
$entry = array(
'tanggal' => $form_state['values']['tgl'],
);
$tabel = 'jp_1';
$return = insert_form($entry,$tabel);
}
.....
function insert_form($entry,$tabel){
$return_value = NULL;
try {
$return_value = db_insert($tabel)
->fields($entry)
->execute();
}
.....
and now i have no problem delivering to mysql.
Hope that will help other drupal newbie developer like me. Thanks :D
$data = array (
'next' => "NOW() + 5",
'interval' => $dom["USER"][0]["STATUSES_COUNT"][0]["data"],
'good' => $good,
'tries' => $p->tries + 1
);
$where = $service->getAdapter()->quoteInto('id = ?', $p->id);
$service->update($data, $where);
to insert something to a database using PHP on zend and mySQL.
The "next" => "NOW()" wont work. I could put the CURRENT_TIMESTAMP as default value, but what i actually want is to insert the timestamp refering this moment, plus some time.
I could rewrite some parts of the program to use pure php dates(instade of pure mySQL dates). Dont know what is best, or what should i do. Do you know how i could make this update work with mySQL doing the timing?
I solved it with the next statement, very usefull:
'next' => new Zend_Db_Expr('TIMESTAMPADD(MINUTE,1,NOW())'),