• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is there any way to pass mysql's NOW() to mysql ?

#1
[eluser]soupdragon[/eluser]
trying to use active record

is there any way to pass mysql's NOW() to mysql ?
$insertarray['id'] = '';
foreach($sellerdata as $what => $details) {
if($what != 'passconf') {
$insertarray[$what] = $details;
}
}
$insertarray['confirmed'] = 'no';
$insertarray['paid'] = '';
$insertarray['datepaid'] = '';
$insertarray['lastlogin'] = NOW();
$insertarray['login_count'] = '0';
$insertarray['status'] = 'dead';
if($this->db->insert('sellers',$insertarray)) {


if not whats a viable alternative - not wanting to rely on php's time/date functions
thanks

#2
[eluser]xwero[/eluser]
You can try to single out the field
Code:
foreach($sellerdata as $what => $details) {
if($what != ‘passconf’) {
$insertarray[$what] = $details;
}
}
$insertarray[’confirmed’] = ‘no’;
$insertarray[’paid’] = ‘’;
$insertarray[’datepaid’] = ‘’;
$insertarray[’login_count’] = ‘0’;
$insertarray[’status’] = ‘dead’;

$this->db->set('lastlogin', 'NOW()',false);
$this->db->set($insertarray);
$this->db->insert('sellers');

#3
[eluser]soupdragon[/eluser]
stunning response time !

and works perfectly :-)

thanks

#4
[eluser]Ignacio[/eluser]
Yup, that works for me too but...

Code:
//Data
$data = array(
    'ID' => '',
    'Hash' => $params['file_name'],
    'DateUploaded' => 'NOW()'
);    

//Insert
$this->db->insert('Photos', $data);

//Idea produces:
//INSERT INTO Photos (ID, Hash, DateUploaded) VALUES ('', '326248800480e3fde00ea4', 'NOW()')

It doesn't work, but it should, don't you think?

#5
[eluser]gtech[/eluser]
I think when you insert values using the active record quotes are escaped.. the purpose of the $this->db->set('DateUploaded', 'NOW()',false); is to ensure 'NOW()' is not escaped (the false parameter tells the set not to escape 'NOW()').

does this work?
Code:
//Data
$data = array(
    'ID' => '',
    'Hash' => $params['file_name']
);  

$this->db->set('DateUploaded', 'NOW()',false);
$this->db->set($data);

$this->db->insert('Photos');

#6
[eluser]Ignacio[/eluser]
Yes, I'm using that way right now and it works fine, but like I said, it "should" work in the other way too.

#7
[eluser]Pascal Kriete[/eluser]
It doesn't work for the exact reason that gtech mentioned. Insert is always escaped for security reasons.

#8
[eluser]gtech[/eluser]
when you pass your params through the insert function all the quotes have slashes added to them as the set() function is called within the insert() function with escape set to TRUE.

it would be the same as doing:
Code:
//Data
$data = array(
    'ID' => '',
    'Hash' => $params['file_name']
);  
//use true instead and value will be inserted as \'NOW()\' meaning 'NOW()' will be inserted into the database.
$this->db->set('DateUploaded', 'NOW()',TRUE);
$this->db->set($data);

$this->db->insert('Photos');

thats why it wont work, active record is built to escape strings as default.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.