It has been my experience that you want to limit the use of the query() function as much as possible. The other query functions (find, findAll, findBy[FieldName], generateList, field, etc) provide a level of abstraction so your code works with different types of databases (not just MySQL) and it also prevents SQL injection.
By customizing your Book model, in your case, you can compensate for your database and tables not being in the standard CakePHP conventions. The $primaryKey and $useTable model attributes help you customize it, as well as the different model relation attributes such as $hasMany, $hasAndBelongsToMany, $hasOne, $belongsTo, which lets you specify the foreignKey value. So to directly answer your question, in you getBibNum() function, I would use the built in field() function instead of query() and pass it some conditions: function getBibNum($isbn) { $conditions = array("`Book`.`tag`='020'", "`Book`.`text` LIKE '% {$isbn}%'"); return $this->field('bib_number', $conditions); } I'm hoping that the field name for the Bib Number is not really 'bib#'... I hope this helps! On Sep 27, 8:53 am, Cory Dee <[EMAIL PROTECTED]> wrote: > Disclaimer: I am very new to Cake > > I havn't had much success searching for examples and tutorials using > the query() function, so I tried to stumble through it with the info I > did have at hand. If someone could point out the errors of my ways, > that'd be awesome. > > Basically, I'm connecting to the DB used by a desktop app we license > from a vendor, so of course, it's not setup in the way Cake would like > it to be. What I am trying to do is something like this: > > Model: > <? > class Book extends AppModel > { > var $name = 'Book'; > function getBibNum($isbn) > { > $ret = $this->query("SELECT [bib#] FROM [bib] WHERE [tag] = > '020' > AND [text] LIKE '%" . $isbn . "%'"); > $bibNum = $ret[0]['bib#']; > return $bibNum; > }} > > ?> > > Controller: > <?php > class BooksController extends AppController > { > var $name = 'Books'; > > function index() > { > //$this->set('posts',$this->Post->findAll()); > $this->set('book', $this->Book->getBibNum("0670063622")); > }} > > ?> > > View: > <h1><?php echo r("\n", "<br/>", $post['Book']['bib#'])?></h1> > > Obviously this is a low level sample, to get me going in the right > direction. Again, tips are appreciated. > > Cory --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---