Код (Text): CREATE DATABASE users; CREATE TABLE `users` ( `email` int(10) UNSIGNED NOT NULL, `name` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `dt_add` varchar(255) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=utf8; insert into users (email, name, password, dt_add) VALUES (kbuttress0@1und1.de, Karrie Buttress, JcfoKBYAB4k, 2019 - 08 - 10); insert into users (email, name, password, dt_add) VALUES (baymer1@hp.com, Bob Aymer, ZEE54kg, 2018 - 12 - 21); insert into users (email, name, password, dt_add) VALUES (zboulding2@macromedia.com, Zilvia Boulding, VJyMV1Zat, 2019 - 07 - 25); insert into users (email, name, password, dt_add) VALUES (emollon3@bloglovin.com, Emalee Mollon, XUIeJ693h, 2018 - 11 - 13); insert into users (email, name, password, dt_add) VALUES (mmulberry4@cmu.edu, Maria Mulberry, oWspnl, 2019 - 07 - 20); insert into users (email, name, password, dt_add) VALUES (lby5@mozilla.com, Levey By, GdtcUU, 2019 - 02 - 12); insert into users (email, name, password, dt_add) VALUES (beates6@last.fm, Baron Eates, UQw6VeA, 2019 - 05 - 03); insert into users (email, name, password, dt_add) VALUES (tvink7@fotki.com, Trip Vink, 49znXd7haFGz, 2019 - 01 - 13); insert into users (email, name, password, dt_add) VALUES (bterbeck8@about.me, Boonie Terbeck, unCjJTF7sjs, 2019 - 09 - 15); insert into users (email, name, password, dt_add) VALUES (atraviss9@auda.org.au, Alonzo Traviss, dLuVMAg, 2018 - 12 - 19); insert into users (email, name, password, dt_add) VALUES (nwitteringa@google.com.br, Natassia Wittering, tQlUG4n, 2019 - 03 - 24); insert into users (email, name, password, dt_add) VALUES (fbrookeb@nba.com, Felice Brooke, s9y9Mcfgy1g, 2019 - 09 - 27); insert into users (email, name, password, dt_add) VALUES (cviccaryc@amazon.co.uk, Carlen Viccary, 9qd747vh, 2018 - 12 - 06); insert into users (email, name, password, dt_add) VALUES (hgethingsd@sogou.com, Hendrik Gethings, zzN5c4, 2018 - 11 - 18); insert into users (email, name, password, dt_add) VALUES (dgirodiase@stanford.edu, Dunc Girodias, j9QW6GQI, 2018 - 10 - 14); insert into users (email, name, password, dt_add) VALUES (btanmanf@smh.com.au, Bibbie Tanman, 1aukKNEIneq, 2019 - 05 - 03); insert into users (email, name, password, dt_add) VALUES (bbartolettig@simplemachines.org, Barnabas Bartoletti, 3chTNtqhoo, 2018 - 12 - 25); insert into users (email, name, password, dt_add) VALUES (nculliph@fc2.com, Nixie Cullip, 2UdKIR2f, 2019 - 04 - 07); insert into users (email, name, password, dt_add) VALUES (mpimblotti@xing.com, Matilde Pimblott, nGZ8disdg, 2019 - 07 - 18); insert into users (email, name, password, dt_add) VALUES (askurrayj@un.org, Al Skurray, bL9tAf, 2018 - 11 - 25); insert into users (email, name, password, dt_add) VALUES (kbuttress0@1und1.de, Karrie Buttress, JcfoKBYAB4k, 2019 - 08 - 10); insert into users (email, name, password, dt_add) VALUES (baymer1@hp.com, Bob Aymer, ZEE54kg, 2018 - 12 - 21); insert into users (email, name, password, dt_add) VALUES (zboulding2@macromedia.com, Zilvia Boulding, VJyMV1Zat, 2019 - 07 - 25); insert into users (email, name, password, dt_add) VALUES (emollon3@bloglovin.com, Emalee Mollon, XUIeJ693h, 2018 - 11 - 13); insert into users (email, name, password, dt_add) VALUES (mmulberry4@cmu.edu, Maria Mulberry, oWspnl, 2019 - 07 - 20); insert into users (email, name, password, dt_add) VALUES (lby5@mozilla.com, Levey By, GdtcUU, 2019 - 02 - 12); insert into users (email, name, password, dt_add) VALUES (beates6@last.fm, Baron Eates, UQw6VeA, 2019 - 05 - 03); insert into users (email, name, password, dt_add) VALUES (tvink7@fotki.com, Trip Vink, 49znXd7haFGz, 2019 - 01 - 13); insert into users (email, name, password, dt_add) VALUES (bterbeck8@about.me, Boonie Terbeck, unCjJTF7sjs, 2019 - 09 - 15); insert into users (email, name, password, dt_add) VALUES (atraviss9@auda.org.au, Alonzo Traviss, dLuVMAg, 2018 - 12 - 19); insert into users (email, name, password, dt_add) VALUES (nwitteringa@google.com.br, Natassia Wittering, tQlUG4n, 2019 - 03 - 24); insert into users (email, name, password, dt_add) VALUES (fbrookeb@nba.com, Felice Brooke, s9y9Mcfgy1g, 2019 - 09 - 27); insert into users (email, name, password, dt_add) VALUES (cviccaryc@amazon.co.uk, Carlen Viccary, 9qd747vh, 2018 - 12 - 06); insert into users (email, name, password, dt_add) VALUES (hgethingsd@sogou.com, Hendrik Gethings, zzN5c4, 2018 - 11 - 18); insert into users (email, name, password, dt_add) VALUES (dgirodiase@stanford.edu, Dunc Girodias, j9QW6GQI, 2018 - 10 - 14); insert into users (email, name, password, dt_add) VALUES (btanmanf@smh.com.au, Bibbie Tanman, 1aukKNEIneq, 2019 - 05 - 03); insert into users (email, name, password, dt_add) VALUES (bbartolettig@simplemachines.org, Barnabas Bartoletti, 3chTNtqhoo, 2018 - 12 - 25); insert into users (email, name, password, dt_add) VALUES (nculliph@fc2.com, Nixie Cullip, 2UdKIR2f, 2019 - 04 - 07); insert into users (email, name, password, dt_add) VALUES (mpimblotti@xing.com, Matilde Pimblott, nGZ8disdg, 2019 - 07 - 18); insert into users (email, name, password, dt_add) VALUES (askurrayj@un.org, Al Skurray, bL9tAf, 2018 - 11 - 25); При импорте в БД phpmyadmin отдат ошибку Статический анализ: Найдено 1 ошибок при анализе. Ожидалось имя символа! (near ")" at position 179) SQL запрос: CREATE TABLE `users` ( `email` int(10) UNSIGNED NOT NULL, `name` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `dt_add` varchar(255) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=utf8 Ответ MySQL: #1046 - База данных не выбрана
после того как починишь create table: строки и даты должны быть в одинарных кавычках. к тому же внутри даты лишние пробелы. сейчас это арифметическое выражение с тремя числами, а не дата.
Код (Text): if (!file_exists($this->sqlFile) && !is_dir($structure)) { mkdir($structure); $this->sqlFileObj = new \SplFileObject($this->sqlFile, "w"); $createDb = "CREATE DATABASE " . $this->dbName . ";"; $this->sqlFileObj->fwrite($createDb); $useQuery = "use " . $this->dbName . ";"; $this->sqlFileObj->fwrite($useQuery); $createTable = "CREATE TABLE " . $this->tableName . "(" . implode(',', $this->columns) . ")" . "ENGINE=InnoDB DEFAULT CHARSET=utf8" . "; "; $this->sqlFileObj->fwrite($createTable); foreach ($this->getNextLine() as $line) { $this->result[] = $line; } foreach ($this->result as $results) { $results = str_replace(";", ",", str_replace(";;;", ',', implode(', ', $results))); $headerQuery = implode(",", $header_data); $contentQuery = "insert into" . " $this->dbName " . "(" . $headerQuery . ")" . " VALUES " . "(" . implode("''", $results) . " ); "; file_put_contents($this->sqlFile, $contentQuery, FILE_APPEND); } echo "Files was successfully created"; } Код (Text): $contentQuery = "insert into" . " $this->dbName " . "(" . $headerQuery . ")" . " VALUES " . "(" . implode("''", $results) . " ); "; - в данном примере результаты в массиве $results, не посоветуете как мне раскрыть массив и обернуть в ' '? implode не видит ' ' и лепит мне ошибку
Как-то всё замудрённо. Зачем инсертить в цикле, может лучше подготовить запрос, а потом один раз вставить?