我想在CakePHP中创建自己的
MySQL查询.
原文链接:https://www.f2er.com/php/130756.html这是我的LocationsController.PHP:
<?PHP App::uses('Location','Model'); class LocationsController extends AppController { public $helpers = array('Html','Form'); function index() { $this->loadModel("Location"); $this->Location->get(); } }
这是我的LocationModel.PHP:
<?PHP App::uses('AppModel','Model'); class LocationModel extends Model { public $name = 'Location'; public function get() { $this->Location->query("SELECT * FROM locations;"); } }
正如您所看到的,我只是尝试执行一个简单的查询,但它不起作用.我收到此错误:
Error: sqlSTATE[42000]: Syntax error or access violation: 1064 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 'get' at line 1
当我使用诸如find(“all”)之类的魔术方法时,它可以工作……
你能看出问题所在吗?我真的不能,我只是想做一个简单的任务!