how to use db lib for direct query?
how to use db lib for direct query?
janosh0511
Posts: 1Questions: 1Answers: 0
hi, i would like to use the php lib for accessing the db. the following code seems to generate an error:
```
<?php
include('./php/lib/DataTables.php');
$data = $db->query("SELECT * FROM rc")->fetchAll();
print_r($data);
<?php > ``` Output of the script: Fatal error: Call to undefined method DataTables\Database\DriverMysqlQuery::fetchAll() in /srv/www... ?>How could I fix it?
This discussion has been closed.
Answers
You want to use the
sql
method, notquery
:```js
<?php
include('./php/lib/DataTables.php');
$data = $db->sql("SELECT * FROM rc")->fetchAll();
print_r($data);
<?php > ``` ?>query
is an object builder, whilesql
will execute any arbitrary SQL string. Docs for this are here.Allan