Friends,
I am creating class to create table and have tried with below script passing array to bindParam. but it's giving me below sql syntax error I really can't figure out what it is. please help on this.
public function generate_table($Table_Name, array $Table_Elements) {
$array_elements = implode(', ', $Table_Elements);
if ($this->db) {
$qry = 'CREATE TABLE IF NOT EXISTS ? (?);';
$stmt = $this->db->prepare($qry);
$stmt->bindParam(1, $Table_Name, PDO::PARAM_STR);
$stmt->bindParam(2, $array_elements, PDO::PARAM_STR);
$stmt->execute();
if ($stmt->errorInfo()) {
var_dump($stmt->errorInfo());
}
if (!$stmt->errorInfo() && $stmt) { echo "Table Created";}
}
}
array(3) { [0]=> string(5) "42000" [1]=> int(1064) [2]=> string(226) "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 ''STU_INFO' ('STU_ID INT NOT NULL AUTO_INCREMENT, STU_FIRST_NAME VARCHAR(25) NOT ' at line 1" }
I am passing array to script like below
$obj = new Create_Table('/home/ubuntu/workspace');
$obj->generate_table('STU_INFO', array ('STU_ID INT NOT NULL AUTO_INCREMENT',
'STU_FIRST_NAME VARCHAR(25) NOT NULL',
'PRIMARY KEY (STU_ID)'));