Jump to content

Customers Bad SQL query


Recommended Posts

I'm using prestashop 1.5.4.1.

 

I just discovered that when I go to Customers > Customers I get the following message:

 

Bad SQL query

Unknown column 'g.id_customer' in 'where clause'

 

I have an old DB backup which I replaced this one with, and there it works like it should.

 

The only problem is that the backup was made BEFORE I added all product images when I imported them. And I really don't feel like or have the time to start editing all of the products once more.

 

Is it possible to copy something from the old DB with the working customers page into the new one with the broken page?

Link to comment
Share on other sites

I just want the customers page to work and something tells me it's an easy fix, just replace something from the working DB backup to the active non-working DB.

 

But I have no idea what to replace lol

 

All the other pages under Customers works, so I can go through Groups and see all customers there.

But as I said it's just annoying that it doesn't work as it should.

 

Any idea what to replace to make the " unknown column 'g.id_customer' in 'where clause' " work? :D

 

I found a link somewhere on the forum with a code to run in phpadmin to truncate customers but I got some error message doing it. So I had to delete the customers under ps_customers instead.

Link to comment
Share on other sites

You could copy the customer tables form the backup database that works and add them to the broken database.

open the backup database in a text editor like Notpade++ (free) and copy the following tables.

 

BACKUP DATABASE FIRST.

 

ps_address

 

pr_customer

pr_customer_group

pr_customer_message

pr_customer_message_sync_imap

pr_customer_thread

 

 

In the database use sql query and paste the copied tables to the text area and run query.

You may need to delete the tables first this depends on the options you chose when you exported the database.

Link to comment
Share on other sites

Do you have a table ps_guest??

It looks like one of those 2 sql statements give the problem, and both want to use this table:

 

From file: /controllers/admin/AdminCustomersController.php:

 

$this->_select = '

a.date_add,

IF (YEAR(`birthday`) = 0, "-", (YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5) < RIGHT(birthday, 5))) AS `age`, (

SELECT c.date_add FROM '._DB_PREFIX_.'guest g

LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest

WHERE g.id_customer = a.id_customer

ORDER BY c.date_add DESC

LIMIT 1

) as connect';

 

 

or from file classes/Customer.php:

 

 

SELECT DISTINCT c.*

FROM `'._DB_PREFIX_.'customer` c

LEFT JOIN `'._DB_PREFIX_.'guest` g ON g.id_customer = c.id_customer

LEFT JOIN `'._DB_PREFIX_.'connections` co ON g.id_guest = co.id_guest

WHERE co.`ip_address` = \''.ip2long(trim($ip)).'\'');

 

(probably last one)

 

So check if you have this guest table, and this field in there.

 

My 2 cents,

pascal

Link to comment
Share on other sites

i think that the problem is a bit different, i suppose that that these two tables and their fields exist, but there is something wrong with the consistency of the database, for example, the missing entries where other one trying to use missed entries index - and this index of course doesn't exist

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...
  • 1 month later...

Hi Vekia, yes I've checked it,

 

I think I have detected the problem but I don´t know how to solve it.

 

My prestashop version es 1.4.7.0.

 

In the file \adminxxx\tabs\admincustomers.php  at the begining there is a sentence like this:

 

$this->_select = '(YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5)<RIGHT(`birthday`, 5)) as age, (
SELECT c.date_add FROM '._DB_PREFIX_.'guest g
LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest
WHERE g.id_customer = a.id_customer
ORDER BY c.date_add DESC
LIMIT 1
) as connect';
 
Really I don´t know anything about this sentence, I only know that if I remove the "_ " from the select, like this:
 
$this->select = '(YEAR(CURRENT_DATE)-YEAR(`birthday`))ssssss
 
then all my customers appear when I click in the tab customers, but I have a notice from ny php that says "in the line admintabs.php 1526 there isn´t index connect"
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...