guillanBesada
guillanBesada

Reputation: 169

How do I connect Prestashop with an external database?

hello I am creating a module to connect from prestashop with an external database. It is on the same server but it is a different database from prestashop. I am using this code that should show the product name with id = 1 in the right sidebar. I have tried a hello world and it shows it without problems, but for some reason when trying to connect with the external database the page does not show me anything. This is the code for the hook function that should show me the name of the product in the right sidebar, what's wrong?

public function hookDisplayLeftColumn($params)
    {
        $db = new Db("localhost","u117490907_ferreteria", "miPassword","u117490907_ferreteria", $connect = true);
    $item_name = $db::getInstance()->getValue('SELECT nombre FROM productos WHERE id = 1');
        return($item_name);
    }

Upvotes: 0

Views: 503

Answers (1)

Arun Vishwakarama
Arun Vishwakarama

Reputation: 166

You can not instantiate DB class as it is Abstract class

Though you can get desired output by using below

$db = new DbMySQLi("localhost","u117490907_ferreteria", "miPassword","u117490907_ferreteria",true);
$item_name = $db->getValue('SELECT nombre FROM productos WHERE id = 1');
return($item_name);

Upvotes: 1

Related Questions