I want to use this method to get array of keys (primary, foreign, ...) from specified table:
public function getTableKeys($table){
//OBTAIN TABLE KEYS
try {
$conn = $this->db->_pdo;
$conn->beginTransaction();
$query = $this->db->_pdo->prepare('SHOW KEYS FROM :table');
$query->bindParam(':table', $table, PDO::PARAM_STR);
$query->execute();
$keys = $query->fetchAll(PDO::FETCH_ASSOC);
$conn->commit();
return $keys;
}catch (Exception $e) {
$conn->rollback();
echo 'Caught exception: ', $e->getMessage(), "\n";
return false;
}
}
The problem is, there is an error thrown:
Caught exception: 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 ''ps_customer'' at line 1
Now if I run SQL manually in PHPMyAdmin, it successfully returns a set of keys. The problem is that it has to be in following format:
SHOW KEYS FROM ps_customers
not in this format (with quotes):
SHOW KEYS FROM "ps_customers"
My question is: How do I bindParam parameter that needs to be inserted into SQL without quotes but is in fast a string (use of PDO::PARAM_INT doesn't work).
Thanks for possible suggestions, guys.