-1

I need to initialize my database, so I create a .php file with PDO connect to create my database.

This is actually working, but the probleme is only the first 22 rows are created. Why?

this is a part of my code:

$pdo->query("
INSERT INTO `photos` 
    (`id`, `url`, `description`, `numero`) 
VALUES 
    (1, 'url', 'des', 'int'),
    (2, 'url', 'des', 'int'),
    (3, 'url', 'des', 'int'),
    (4, 'url', 'des', 'int'),
    (5, 'url', 'des', 'int'),
    (6, 'url', 'des', 'int'),
[...]
    (698, 'url', 'des', 'int'),
    (699, 'url', 'des', 'int'),
    (700, 'url', 'des', 'int');");

Thanks.

samuel
  • 477
  • 7
  • 21
  • 1
    [MySQL - how many rows can I insert in one single INSERT statement?](https://stackoverflow.com/questions/3536103/mysql-how-many-rows-can-i-insert-in-one-single-insert-statement#3536148) – Lukasz Szozda Sep 01 '19 at 15:12
  • 1
    Can you show the data around that particular part of the INSERT as it may be data related. – Nigel Ren Sep 01 '19 at 15:12
  • Ok, I think I understand. If I want to add 700 rows, one solution is to make a lot of query (70 insert of 10 lines for example) – samuel Sep 01 '19 at 15:17

1 Answers1

0

Your query string may be too long. Do you get any error messages?

Anyway, a better approach would be to use prepared statements. Prepare the insert statement once and execute it as often as needed with the values you need to add to the table. This should be much faster as parsing and executing a single huge request.

Florian Schwalm
  • 166
  • 1
  • 3