Search code examples
crmvtigervtigercrm

How can i access the Vtiger Database object?


I am writing a php script to import some data into my custom module, basically i will run a cron job periodically to copy some data from another table to populate my custom module fields.

Thanks.


Solution

  • Use PearDatabase.php class to get database access and functions related to the DB operations.

    Example:

    <?php
    include_once 'include/database/PearDatabase.php';
    $db = PearDatabase::getInstance();
    $result = $db->pquery("SHOW TABLES LIKE 'leads'", array());
    echo $db->num_rows($result);
    print_r($result);
    echo "<br>Test Done <br>";
    
    
    //Using $db object you can access other DB related methods defined in that class.
    //Include the file in your module in any file where you want DB operation.
    // But I would recommend, use inside your main module class or model controller class.
    ?>
    

    Put this PHP script into your root directory and run directly this file using your browser. So you will get some idea and you can able to use inside your module because all module loads from index.php file (root directory).