I have a query about how to implement my use case.I have a set of arrays that I want to insert in the DB,but now I am confused how can I do it efficiently.I am using PHP and MySQL.Below is the use case:
$shareUrl = array();
$theInsertUrl = array();
$authKeyArray = array();
Above are the arrays I get after processing some information.Now I have to insert it into the DB,but instead of doing it one by one,I thought have a single insert would be better solution(Please correct if not).
For multiple insert the values part of my SQL query must have
($shareUrl[0],$theInsertUrl[0],$authKeyArray[0]),($shareUrl[1],$theInsertUrl[1],$authKeyArray[1]),...
I thought of writing a for loop and create a multidimensional array like this
for($i=0;$i<count_of_array;$i++){
$multiArray[$i]['shareUrl'] = $shareUrl[0];
$multiArray[$i]['theInsertUrl'] = $theInsertUrl[0];
$multiArray[$i]['authKeyArray'] = $authKeyArray[0];
}
But still it will be tedious to use this in the SQL query's values part as it accepts a format like this ('val1','val2'),('val1','val2'). I need suggestions on how can I go about implementing it? Is the above approach correct or is there a better solution OR should I go it with single insert statements?
mysql_functions,mysqliorPDO? Some numbers would also help, like how big the array is.mysqlifunctions! Actually I am doing it for a file sharing app.So there can be many inserts simultaneously!Initially though the number won't be significant,it will grow quickly as I progress!mysqli, jumped from mysql to PDO, I'm not sure ifmysqlihas named parameters binding, as far as I know you can use question marks?in order, but not :value1 like in PDO. So i'm not sure on the implementation, better let someone more experienced inmysqlito answer you. BTW you should use the prepared statements inmysqli, or you are not really being injection safe