[英]How to execute custom query in cakephp 3.x
Custom query execution in cakephp. 在cakephp中执行自定义查询。 I have applied below code.
我已应用以下代码。
$conn = ConnectionManager::get('default');
$rs = $conn->query('SELECT * FROM customers');
It gives me blank array though customers
table has 20 records. 虽然
customers
表有20条记录,但它给了我空白数组。
Please suggest me some solution. 请给我一些解决方案。
Thanks. 谢谢。
It's not recommended but somtimes there is no other way! 这不是推荐的,但有时没有别的办法! :
:
You should mention namespace of connection manger 你应该提到连接管理器的命名空间
use Cake\\Datasource\\ConnectionManager;
Get/initialize a connection 获取/初始化连接
$conn = ConnectionManager::get('default');
Execute SQL with something like this 用这样的东西执行SQL
$stmt = $conn->execute('SELECT * FROM customers');
Fetch the results 获取结果
$results = $stmt ->fetchAll('assoc');
See also 也可以看看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.