Как я могу реализовать рекурсивные запросы MySQL. Я пытаюсь найти его, но ресурсы не очень полезны.
Попытка реализовать подобную логику.
public function initiateInserts() { //Open Large CSV File(min 100K rows) for parsing. $this->fin = fopen($file,'r') or die('Cannot open file'); //Parsing Large CSV file to get data and initiate insertion into schema. $query = ""; while (($data=fgetcsv($this->fin,5000,";"))!==FALSE) { $query = $query + "INSERT INTO dt_table (id, code, connectid, connectcode) VALUES (" + $data[0] + ", " + $data[1] + ", " + $data[2] + ", " + $data[3] + ")"; } $stmt = $this->prepare($query); // Execute the statement $stmt->execute(); $this->checkForErrors($stmt); }
@Author: Numenor
Сообщение об ошибке: у 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 '0' at line 1
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 '0' at line 1
Этот подход вдохновил на поиск рекурсивного запроса MySQL.
Вот подход, который я использовал раньше:
public function initiateInserts() { //Open Large CSV File(min 100K rows) for parsing. $this->fin = fopen($file,'r') or die('Cannot open file'); //Parsing Large CSV file to get data and initiate insertion into schema. while (($data=fgetcsv($this->fin,5000,";"))!==FALSE) { $query = "INSERT INTO dt_table (id, code, connectid, connectcode) VALUES (:id, :code, :connectid, :connectcode)"; $stmt = $this->prepare($query); // Then, for each line : bind the parameters $stmt->bindValue(':id', $data[0], PDO::PARAM_INT); $stmt->bindValue(':code', $data[1], PDO::PARAM_INT); $stmt->bindValue(':connectid', $data[2], PDO::PARAM_INT); $stmt->bindValue(':connectcode', $data[3], PDO::PARAM_INT); // Execute the statement $stmt->execute(); $this->checkForErrors($stmt); } }
public function initiateInserts() { //Open Large CSV File(min 100K rows) for parsing. $this->fin = fopen($file,'r') or die('Cannot open file'); //Prepare insertion query to insert data into schema. $query = "INSERT INTO dt_table (id, code, connectid, connectcode) VALUES (:id, :code, :connectid, :connectcode)"; $stmt = $this->prepare($query); // Then, for each line : bind the parameters $stmt->bindValue(':id', $data[0], PDO::PARAM_INT); $stmt->bindValue(':code', $data[1], PDO::PARAM_INT); $stmt->bindValue(':connectid', $data[2], PDO::PARAM_INT); $stmt->bindValue(':connectcode', $data[3], PDO::PARAM_INT); //Loop through CSV file and execute inserts prepared, but this is not working //and there are not data being populated into database. while (($data=fgetcsv($this->fin,5000,";"))!==FALSE) { // Execute the statement list($id, $code, $connid, $conncode)=$data; $stmt->execute(); $this->checkForErrors($stmt); } }
Это был мой главный вопрос, для которого я ищу предложения!