codes table
id code
-- ------
1 BB3CA4
2 2788BA
3 E3E3A5
. .
. .
. .
PHP array of 500 semi-unique strings called $codes to be added to the codes table:
$codes = array( 'AC2BE4', 'BC61A2', '34CE5A', ... );
My PDO database connection object:
$dbh = new PDO( "mysql:host=$host;dbname=$db", $user, $pass );
Try 1
Put PDO insert execute within the PHP loop:
foreach( $codes as $code ){
$stmt = $dbh->prepare("INSERT INTO codes ( code ) VALUES ( :code )");
$stmt->bindParam( ':code', $code , PDO::PARAM_STR );
$stmt->execute();
}
I think this is not a good solution!
Try 2
Second try was to construct a long SQL query by gluing 500 SQL queries and run it at once.