how to use db lib for direct query?

how to use db lib for direct query?

janosh0511janosh0511 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?

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    You want to use the sql method, not query:

    ```js
    <?php

    include('./php/lib/DataTables.php');

    $data = $db->sql("SELECT * FROM rc")->fetchAll();

    print_r($data);

    <?php > ``` ?>

    query is an object builder, while sql will execute any arbitrary SQL string. Docs for this are here.

    Allan

This discussion has been closed.