PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 26, 2022

[FIXED] How do I connect Prestashop with an external database?

 October 26, 2022     php, prestashop-1.7     No comments   

Issue

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);
    }

Solution

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);


Answered By - Arun Vishwakarama
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing