I am trying to create a prepared mysqli statement in which I import tables from an odbc-linked database into a mysql database, I get this error with a 106-column table query.
You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use near '? (ID, column1, column2, column3, column4, 'in row 1 "
When I repeat the request here, he ...
INSERT IN? (ID, column1, column2, column3, column4, ... 106 full columns ...) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,? [Alpha], [alpha], [alpha], [alpha], [alpha], [alpha], [alpha], [alpha], [alpha], [alpha], [alpha], [alpha], & alpha ;, alpha ;, alpha ;, alpha ;, alpha ;, alpha ;, alpha ;, alpha; alpha ;, alpha ;, alpha ;, alpha; alpha ;, α, α, α, α, α, α, α, α, α, α, α, α , α, α, α, α, α, α, α,?
$sql = "SELECT * FROM $table WHERE $key = '$acct'"; $link = getODBCConnection(); $result = odbc_do($link, $sql); $data = array(); while ($row = odbc_fetch_array($result)) { //store all query rows as array array_push($data, $row); } //insert into mysql table of the same name //get column count from first row $columns = count($data[0]); $params = str_repeat(" ?,",$columns); $params = rtrim($params,','); $types = str_repeat("s",$columns+1); $fields = implode(", ", array_keys($data[0])); $sql = "INSERT INTO ? ($fields) VALUES ($params) ON DUPLICATE KEY UPDATE"; echo $sql."<br>"; $link = getSalesConnection(); $stmt = $link->prepare($sql); var_dump($link->error); foreach ($data as $row) { $stmt->bind_param($types, $table, implode(", ",array_values($row))); $stmt->execute(); }
I tried this with the standard bind_param and also with the call_user_func_array () method. I tried referencing parameter strings and column names without effect. If there was an error with my bind_param types, I should not have an error in the preparation statement, should I? But there are some problems with SQL going to the preparation team, which I cannot determine. Please, help!