Topic: updateProperty: Insert date causes SQL error (Read 1628 times)
Total Zero
Posts: 5
34 credits Members referred : 0
« on: Nov 29, 2009, 06:35:23 pm »
Hi there. I am using the modified class from Downlord and I am trying to insert a date into the DB. But whatever I write I always get a MySQL error like ? You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\"2009-11-29 17:53:49\" WHERE id = 1'.
Other MySQL commands (the first two) work fine. But how do I have to write and formate the date to pass it through and save it? $update = array( 'loginCount' => 'loginCount+1', 'lastLogin' => 'NOW()', 'lastVisit' => '"2009-11-29 17:53:49"' ); $user->updateProperty($update);?>
That is the updateProperty method from the userclass: public function updateProperty($properties) { if(is_array($properties) && count($properties) > 0) { $i=1; $query = "UPDATE ".$this->dbTable." SET ";
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #1 on: Nov 29, 2009, 06:47:47 pm »
It looks like the function is incomplete. Please expect a new version later (I've already have a draft but needs some stuff to release)
Until then update the table with queries. Bellow is an untested updateProperty() function for the new release, but it is not working with mysqli. Maybe you can play with that:
Total Zero
Posts: 5
34 credits Members referred : 0
« Reply #2 on: Nov 29, 2009, 07:22:27 pm »
Thanks for your quick response. The code you posted does help in case I want to insert only strings in the DB but with the backticks at '".$this->escape($v)."'" I can't insert MySQL code anymore (like NOW() for example).
I think the problem is the escape method which escapes the " when I declare a string in my array ('lastVisit' => '"2009-11-29 17:53:49"')
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #3 on: Nov 30, 2009, 01:08:39 am »
If you want this only for the NOW() function you can use the php date() function instead. I know it is better to use NOW() but it will work (at least until we find a fast way to do this with the class)
Total Zero
Posts: 5
34 credits Members referred : 0
« Reply #4 on: Dec 01, 2009, 08:25:00 pm »
I think I stick with the auto escape function in updateProperty and use for some fields the old and ordinary query function of mysql :-)
Total Zero
Posts: 5
34 credits Members referred : 0
« Reply #5 on: Dec 01, 2009, 10:24:27 pm »
I noticed that the query method is a private function. That results in "Fatal error: Call to private method flexibleAccess::query() from context" when I try to update.
Code:
$user->query("UPDATE `{$user->dbTable}` SET `lastVisit` = `2008-09-09 18:18:00`, `lastLogin` = NOW(), `loginCount` = loginCount+1 WHERE `{$user->tbFields['userID']}` = '{$user->userID}' LIMIT 1", __LINE__);
In example3.php you use $user->query() as well.
Code:
if ($user->query("UPDATE `{$user->dbTable}` SET `{$user->tbFields['active']}` = 1 WHERE `activationHash` = '$hash' LIMIT 1", __LINE__))
Can you help?
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #6 on: Dec 02, 2009, 12:20:11 pm »
Yeah, it should be a public function. Just replace "private" with "public" and it will work. This wont affect anything else
Total Zero
Posts: 5
34 credits Members referred : 0
« Reply #7 on: Dec 02, 2009, 10:03:09 pm »
Ok, that's cool :-) Now it works. I had to change {$user->dbTable} and {$user->tbFields['userID']} 'cause they were private as well. I set them directly into my script instead of setting them public. I am not much familiar with OO but I think it is not a bad idea to make theses vars private :-)
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #8 on: Dec 03, 2009, 12:32:39 pm »
I guess after the first php5 release we will have to check several things regarding the future development