Yeah, I use it inside a Shell inheritance. uses('model'.DS.'connection_manager'); $db = ConnectionManager::getInstance(); $dataSource = $db->getDataSource('default'); $sql = '*blahblah*'; $resultSrc = $dataSource->_execute($sql); $results=array(); while($data=$dataSource->fetchResult()) { $results[]=$data; }
The $results will be an array. The only problem is the $results only has the column name. For example: I have 2 tables. table 1 has 2 columns: id, value1; table 2 has another 2 columns: id, value. Both have id column, if I join the two, and select both, only ONE id shows in the result.... Maybe I will use alias to solve this problem... 2009/10/14 Jorge Horacio Cué Cantú <jorge....@gmail.com> > Other difference, > > I am using the $dataSource->_execute() inside a Controller, I untherstand > You want to use it inside a Shell. > > Is this correct?, Is there a difference in environment? > > Regards. > > > El 14 de octubre de 2009 09:27, Yuncong Zhang <njit...@gmail.com>escribió: > > Thank you Jorge, >> >> The syntax is correct. Maybe there are no public properties in that class. >> >> >> I worked it out, using cakephp fetchResult() function. >> >> Yuncong >> >> 2009/10/14 Jorge Horacio Cué Cantú <jorge....@gmail.com> >> >> Hello $dataSource->_execute($sql) calls the untherlying database driver. >>> for example for mysqli it calls mysqli_query(). >>> >>> IMHO should check the mysqli documentation to check the return value. >>> >>> BTW, if there is any sintax error in the SQL statement, then the function >>> normally returns false, are You shure the SQL statement is complete when >>> sent to _execute method?. >>> >>> Regards. >>> >>> El 13 de octubre de 2009 14:02, blah <njit...@gmail.com> escribió: >>> >>>> Hello Jorge, >>>> >>>> I meet similar problem. When I try your method, the console shows >>>> empty mysqli_result Object for any results no matter what SQL I put in >>>> $sql_statement. Do you know why? >>>> >>>> mysqli_result Object >>>> ( >>>> ) >>>> >>>> Thank you in advance. >>>> >>>> Yc Zhang >>>> >>>> On Sep 24, 5:43 pm, Jorge Horacio Cué Cantú <jorge....@gmail.com> >>>> wrote: >>>> > Hello, >>>> > >>>> > I had a similar problem. I have an Install controller that executes a >>>> SQL >>>> > script in ordert to create the database. >>>> > What I have done is somethjing similar to: >>>> > >>>> > uses('model'.DS.'connection_manager'); >>>> > $db = ConnectionManager::getInstance(); >>>> > $dataSource = $db->getDataSource('default'); >>>> > >>>> > // The to execute each SQL statement do: >>>> > >>>> > $result = $dataSource->_execute($sql_statement'); >>>> > if ($result) { >>>> > // success >>>> > >>>> > } else { >>>> > // failure >>>> > } >>>> > >>>> > I hope this helps you. Regards >>>> > >>>> > 2009/9/24 Stinkbug <justink...@gmail.com> >>>> > >>>> > >>>> > >>>> > > I'm somewhat familiar with the schema stuff. However, the .sql file >>>> > > is a file that's going to be provided to us and not a file that will >>>> > > be generated by cake. Our .sql file isn't just about the schema, it >>>> > > could be large amounts of data manipulation using sql. So unless >>>> the >>>> > > schema stuff will execute a .sql file (rather than just generate >>>> it). >>>> > > I don't think it will work for us. That's why I was trying to get >>>> the >>>> > > code above to work. >>>> > >>>> > > Any other thoughts? >>>> > >>>> > > On Sep 23, 4:39 pm, Sam Sherlock <sam.sherl...@gmail.com> wrote: >>>> > > > I think you want to create a schemahttp:// >>>> > > book.cakephp.org/view/735/Generating-and-using-Schema-files >>>> > > > - S >>>> > >>>> > > > 2009/9/23 Stinkbug <justink...@gmail.com> >>>> > >>>> > > > > I'm trying to execute a bunch of sql from a .sql file from the >>>> > > > > console. I was trying to use the query method inside the Model >>>> class, >>>> > > > > but I keep getting the following error. >>>> > >>>> > > > > Error: Missing database table 'models' for model 'Model' >>>> > >>>> > > > > Below is my code: >>>> > >>>> > > > > <?php >>>> > > > > App::import('Core', array('Model')); >>>> > > > > class UpgradeShell extends Shell { >>>> > > > > var $uses = array(); >>>> > >>>> > > > > function main() { >>>> > > > > $filename = APP . 'config/sql/upgrade.sql'; >>>> > > > > if (file_exists($filename)) { >>>> > > > > $handle = fopen($filename, "r"); >>>> > > > > $sql = fread($handle, >>>> filesize($filename)); >>>> > > > > fclose($handle); >>>> > > > > echo $sql; >>>> > > > > if ($sql) { >>>> > > > > //Model::query($sql); >>>> > > > > $model = new Model(); >>>> > > > > //$model->query($sql); >>>> > > > > } >>>> > > > > } >>>> > > > > } >>>> > >>>> > > > > } >>>> > > > > ?> >>>> > >>>> > > > > When I try Model::query($sql); >>>> > >>>> > > > > I get the following error: >>>> > > > > Notice: Undefined property: UpgradeShell::$Model in C:\wamp\www\ >>>> rx.com >>>> > > > > \app\vendors\shells\upgrade.php on line 13 >>>> > >>>> > > > > Fatal error: Call to a member function query() on a non-object >>>> in C: >>>> > > > > \wamp\www\rx.com\app\vendors\shells\upgrade.php on line 13 >>>> > >>>> > > > > I don't really need to specify models, I just want to execute >>>> the >>>> > > > > queries inside the .sql file. >>>> >>> >>> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---