ssp icon indicating copy to clipboard operation
ssp copied to clipboard

SQLSTATE[42000] OR SQLSTATE[42S22]

Open tagplus5 opened this issue 8 years ago • 1 comments

When i set

// Table's primary key
$primaryKey = '`company`.`id`';

in ssp.class on this part

// Total data set length
$count_request = "SELECT COUNT(`{$primaryKey}`)";
if ($joinQuery) {
    $count_request .= $joinQuery;
} else {
    $count_request .= "FROM   `$table`";
}

I get this sql:

SELECT COUNT(``company`.`id``) FROM `company` LEFT JOIN `city` ON `company`.`city` = `city`.`id`

And error

{"error":"An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'company`.`id``) FROM `company` LEFT JOIN `city` ON `company`.`city` = `city`.`id' at line 1"}

And when i set

$primaryKey = 'company.id';

I get this sql:

SELECT COUNT(`company.id`) FROM `company` LEFT JOIN `city` ON `company`.`city` = `city`.`id`

And error

{"error":"An SQL error occurred: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'company.id' in 'field list'"}

I think that need set

$count_request = "SELECT COUNT({$primaryKey})";

without

`

And use

$primaryKey = '`company`.`id`';

tagplus5 avatar Dec 19 '15 22:12 tagplus5

Me too!

alzambo avatar Jan 15 '17 13:01 alzambo