adrianfp2000 Posted May 16, 2024 Share Posted May 16, 2024 Good morning, I am having problems using dbquery to query my database, When I run the following code: <?php $sql = new DbQuery(); $sql->select('*'); $sql->from('ps_orders', 'o'); print($results = Db::getInstance()->executeS($sql)); ?> I get a 500 error from the server, I don't know if this is because the server is rejecting the SQL connection or I am doing something wrong in the code. Link to comment Share on other sites More sharing options...
Prestashop Addict Posted May 16, 2024 Share Posted May 16, 2024 Activate debug mode, you'll see the error Link to comment Share on other sites More sharing options...
adrianfp2000 Posted May 16, 2024 Author Share Posted May 16, 2024 I have it activated and I have an HTTP ERROR 500 Link to comment Share on other sites More sharing options...
WebDesk Solution Posted June 6, 2024 Share Posted June 6, 2024 Hello @adrianfp2000, Here are some corrections in the code. Please use this code to retrieve data from the orders table: <?php // Include PrestaShop configuration file require_once(dirname(__FILE__) . '/config/config.inc.php'); require_once(dirname(__FILE__) . '/init.php'); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); use PrestaShop\PrestaShop\Adapter\Entity\DbQuery; use PrestaShop\PrestaShop\Adapter\Entity\Db; // Create a new DbQuery instance $sql = new DbQuery(); try { // Build the query $sql->select('*'); $sql->from('orders'); // Use the correct table prefix // Execute the query and fetch results $results = Db::getInstance()->executeS($sql); // Check if results are returned and print them if ($results) { echo '<pre>'; print_r($results); } else { echo 'No results found.'; } } catch (Exception $e) { echo 'Error: ' . $e->getMessage(); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now