0

I have a file with 50000 rows. I make a code but it skips lots of row and pages.When i enter in phpmyadmin to look i have like so 1-10 then it start to skip 23-34 78 102 345 546 etc. i think i has something with the execution.

$contents = file_get_contents("testinsert.txt");
$data = explode(PHP_EOL, $contents);


$query = "INSERT INTO table (`name`) VALUES (?)";

$zz = $conn->prepare($query);

$zz ->bind_param("i", $bb);

$conn->query("START TRANSACTION");
foreach ($data as $bb) {
    $zz->execute();`
}

$zz->close();
$conn->query("COMMIT");
8
  • phpMyAdmin is a tool written in PHP, not a database into which you can insert data Commented Jul 28, 2017 at 17:01
  • 2
    Is the backtick really in your code, the one after $zz->execute();` Commented Jul 28, 2017 at 17:02
  • 1
    i know, it was just for explaing lol the data is worng phpmyadmin Commented Jul 28, 2017 at 17:02
  • 1
    It would be useful to see some of the input file as well as the code that is processing it Commented Jul 28, 2017 at 17:03
  • what is backtick ? Commented Jul 28, 2017 at 17:03

1 Answer 1

1

I am amazed this code does anything: I would expect $zz ->bind_param("i", $bb); to be in the foreach loop. Also it would probably have to read:

foreach ($data as $bb) {
    $zz ->bind_param("s", $bb);
    $zz->execute();
}

(Notice the s for string data)

Sign up to request clarification or add additional context in comments.

3 Comments

You would call bind_param outside the loop as the @OP did
@RamRaider That would only bind once and then on a not initialized variable (unless php has an unseen optimization for out of scope variables?)
do all of the "problem" rows have name field values?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.