Jump to content

[SOLVED] accesing mysql results via Db class


sergito
 Share

Recommended Posts

Hi people, i have a "hello world" module installed in prestashop. It works. One of the php scripts prints a list introduced in the module configuration. This script has the following code:

$sql = "select * from ejemplo order by id desc;";
$result = Db::getInstance() -> ExecuteS($sql);
$smarty->assign('lista',$result);

and it works, the TPL file shows the list. But now i want to assing a simple variable to smarty. I have the following code:

$sql = "select * from ejemplo where id=1;";
$result = Db::getInstance() -> Execute($sql);
$smarty->assign('variable',$result['frasebienvenida']);

The difference between both are "Execute" function. This is for retrieving only one row, like are explaned into Db.php script of prestashop. But it doesn't work. Ive tried with several things like using getRow() function, passing directly $result to smarty and then accesing {$variable.frasebienvenida} but any of this works. the tpl file doesn's show anything. tipping the sql sentence from mysql console shows one row.

can anybody help me?

Share this post


Link to post
Share on other sites

aditional explanation. the following code make tpl to print 'pepe', but assigning $result['frasebienvenida'] doesn't show anything. 'frasebienvenida' exists in table ejemplo.

$sql = "select * from ejemplo where id=1;";
$result = Db::getInstance() -> Execute($sql);
if ($result != null)
$smarty->assign('variable','pepe');
else
$smarty->assign('variable','vacioo');

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More