PHP Classes

mysql functions

Recommend this page to a friend!

      CRDB  >  CRDB package blog  >  Request for feed back  >  All threads  >  mysql functions  >  (Un) Subscribe thread alerts  
Subject:mysql functions
Summary:what has changed?
Messages:6
Author:geert van bommel
Date:2009-03-24 12:04:03
Update:2009-03-26 08:13:00
 

  1. mysql functions   Reply   Report abuse  
Picture of geert van bommel geert van bommel - 2009-03-24 12:04:03
I downloaded your class yesterday and I like it very much. Today you've changed the class to add ability to use mysql functions.
Can you also provide an example use of this?

  2. Re: mysql functions   Reply   Report abuse  
Picture of Sandeep.C.R Sandeep.C.R - 2009-03-25 04:22:42 - In reply to message 1 from geert van bommel
Glad to know you liked the class.

will explain the thing about using mysql functions with class.

normaly if you give as

$db->user(10)->joined_date='2009-10-10', it will expand to something like

"update `user` set `joined_date`='2009-10-10' where `id`=10";

But what if you want to use the NOW() mysql function to insert the current
date in the column,we cannot give as $db->user(10)->joined_date='NOW()'
because it expands to
"update `user` set `joined_date`='NOW()' where `id`=10";
and the string 'NOW()' will get inserted instead of date.we should not put quotes around mysql functions.so instead of giving

$db->user(10)->joined_date='NOW()';

give as

$db->user(10)->joined_date=(object)'NOW()';

casting it to an object makes the class treat it specially and creates the query correctly,with out the quotes around the NOW().Same can be used while
inserting,selecting ex

$db->user=array('name'=>'User_1','joined_date'=>(object)"NOW()");
or while selecting

$name=$db->user->joined_date((object)"NOW()")->name;



  3. Re: mysql functions   Reply   Report abuse  
Picture of Sandeep.C.R Sandeep.C.R - 2009-03-25 04:32:44 - In reply to message 1 from geert van bommel
There was a bug in the mysql functions section.Please download the updated class file.

Thank You.
Sandeep

  4. Re: mysql functions   Reply   Report abuse  
Picture of geert van bommel geert van bommel - 2009-03-25 19:11:27 - In reply to message 3 from Sandeep.C.R
smart thinking. I forgot about the special mysql functions. I thought you meant to be able to add 'sql parts' in case the notation is not flexible enough like for group by, having, distinct,.... or so.

Am I also right when I think you can't use order by on multiple columns?
eg. $crdb->user->name('rlike','abc')->order_by()->no->desc_order_by()->key
In that case ->order_by('no ASC, key DESC') would be handy. Just an idea :-)

I love the class, simply because it's light, clear and time-saving !



  5. Re: mysql functions   Reply   Report abuse  
Picture of Sandeep.C.R Sandeep.C.R - 2009-03-26 07:46:57 - In reply to message 4 from geert van bommel
I have added the order by and group by with mulitiple fields,though little
different from the way you suggested.

Instead of

$crdb->user->name('rlike','abc')->order_by('no ASC, key DESC')

give as

$crdb->user->name('rlike','abc')->order_by()->fields('no','key DESC',...)

hope this helps.




  6. Re: mysql functions   Reply   Report abuse  
Picture of geert van bommel geert van bommel - 2009-03-26 08:13:00 - In reply to message 5 from Sandeep.C.R
Wow, thanks for the quick adaption. I absolutely love this class :-)