When try to query database from a custom page it gives "Fatal error: Uncaught Error: Call to a member function query()"

Hi,
I have a situation where I need to query the SuiteCRM database from custom/SomePageName.php.
Here is my SomePageName.php

    <?php 

    $GLOBALS['db'];

    $query = 'SELECT * FROM users';
    $results = $GLOBALS['db']->query($query);

    $result = $GLOBALS['db']->query($sql);

    while($row = $GLOBALS['db']->fetchByAssoc($results) )
    {
        $id = $row['id'];
        echo $id;
    }

    ?>

Here I got three main issues:-
(i) Undefined index: db (which get resolved by using global $db instead $GLOBALS[‘db’]),

(ii) Fatal error: Uncaught Error: Call to a member function query(),

(iii) Error: Call to a member function query() on null.

Any suggestion what has gone wrong this?

Is this a registered entry-point?

no, it’s a simple PHP page, under custom directory. Do I need to create entry-point?

I think so. If you want access to the database you need to make sure you’re coming from “approved” code. I think the SuiteCRM classes will block your access if you don’t. There should be entries in suitecrm.log if this happens.

Try it, it’s not hard.

1 Like