PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/include/SQL/SQL_Query_Renderer/docs/example.php

https://github.com/radicaldesigns/amp
PHP | 62 lines | 23 code | 13 blank | 26 comment | 0 complexity | 285e48185dc4f52a0f6554591f6b117a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. /* interesting reads
  3. http://docs.xaraya.com/docs/rfcs/rfc0035.html
  4. this is what it will become one day
  5. http://www.korzh.com/delphi/sq/images/ssmain1.gif
  6. */
  7. //
  8. // a join from ContaX
  9. //
  10. /* QT0.9x its like this
  11. $this->DB_QueryTool(TABLE_CONTACT);
  12. $this->autoJoin( array(TABLE_CONTACT2TREE,TABLE_CONTACTTREE) );
  13. $this->setLeftJoin(TABLE_EMAIL,TABLE_EMAIL.'.contact_id=id AND '.TABLE_EMAIL.'.primaryMail=1');
  14. $this->setWhere(TABLE_CONTACTTREE.".user_id=$userId");
  15. $this->setOrder('surname,name');
  16. */
  17. ini_set('error_reporting',E_ALL);
  18. ini_set('include_path',realpath(dirname(__FILE__).'/../../..'));
  19. #define('DB_DSN', 'mysql://root@localhost/test');
  20. $tableStructures = array(
  21. );
  22. require_once 'SQL/Query.php';
  23. require_once 'SQL/Query/Join.php';
  24. require_once 'SQL/Query/Condition.php';
  25. /*$aliases = array(
  26. TABLE_CONTACT => 'contact'
  27. ,TABLE_CONTACT2TREE => 'contact2tree'
  28. ,TABLE_CONTACTTREE => 'contactTree'
  29. );
  30. */
  31. #DB_QueryTool::addAliases($aliases);
  32. $query = new SQL_Query_Join('contact');
  33. $query->autoJoin('contact2tree','contactTree');
  34. $query->addLeftJoin('email',new SQL_Query_Condition('email.contact_id','=','id','AND','email.primaryMail','=',1));
  35. $query->addWhere('contactTree.user_id','=',7);
  36. $query->addOrder('surname,name');
  37. // this is just to demonstrate nested where clauses, the query doesnt really make sense, at least not to me :-)
  38. // SELECT * FROM user WHERE (name LIKE 'n%' AND name LIKE 'a%') OR name LIKE 's%'
  39. $query = new SQL_Query('user');
  40. $c1 = $query->condition('name','LIKE','"n%"');
  41. $c1->add('name','LIKE','"a%"','AND');
  42. $query->addWhere($c1,'OR',$query->condition('name','LIKE','"%s"'));
  43. require_once 'SQL/Query/Renderer.php';
  44. $render = SQL_Query_Renderer::factory($query,$tableStructures);
  45. print $render->toString();
  46. print "<pre>";
  47. print_r($query);
  48. ?>