Jump to content

Bad SQL Query !


Recommended Posts



I added a tab to BACK-OFFICE with a associated PHP page (AdminMyPage.php).


This is the source of the page :



class AdminMyPage extends AdminTab
private $results;

public function __construct()

// date of the day
$today = getdate();

if ($today['mday'] < 10)
$day = "0" .$today['mday'];
$day = $today['mday'];

if ($today['mon'] < 10)
$month = "0" .$today['mon'];
$month = $today['mon'];

$dateJour = $day . "/" . $month . "/" . $today['year'];

public function displayForm()
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));

$sql = "SELECT count(*) as nb FROM `" . _DB_PREFIX_ . "belvg_CA_customerattributes_customer`
WHERE id_belvg_customerattributes = 1 and value = '" . $dateJour . "' ";

$this->results = Db::getInstance()->ExecuteS($sql);

if ($this->results) {
foreach ($this->results as $row)
echo $row['dt_rdv'].' :: '.$row['nb'].'<br />';
echo "no data !";

When i execute this page (click on my tab / BACK_OFFICE), i have this message :




The query is correct (tested with phpMyAdmin).


Any ideas ? 


thanks you in advance




Link to comment
Share on other sites


Think it is a problem  with $dateJour variable. It is undefined in displayForm () function.

You could move date calulation in displayForm or make dateJaour class variable.


I move date calculation in displayForm (of course) but i have always the same problem : BAD SQL QUERY !

Just a precision : i work with Prestashop 1.6

Link to comment
Share on other sites

Try to turn debug mode on in folder config, file defines.inc.php set 

if (!defined('_PS_MODE_DEV_'))
define('_PS_MODE_DEV_', true);

Maybe it will get some hint what is wrong.


And if you get count maybe to try with this 


Link to comment
Share on other sites

This is the debug message :

Fatal error: Uncaught Table 'mybase.ps_' doesn't exist

            FROM `ps_` a
            WHERE 1
            ORDER BY a.`id_` ASC
            LIMIT 0,50

thrown in /home/xxxxxx/classes/db/Db.php on line 639

very strange !


The name of the table is supplied in my query ! ('ps_belvg_CA_customerattributes_customer')

Link to comment
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
  • Create New...