This is what I normally do to store tags in a database:
foreach ($tags as $tag)
{
if (mysqli_query($link, "INSERT INTO tag (name) VALUES ('$tag')") === false)
{
$queries_ok[] = false; # I'm using this because I have autocommit set to false, i.e. mysqli_autocommit($link, FALSE);
}
}
However this involves connecting to the database several times, so if you have 10 tags, it involves connecting 10 times, is there another, simplier, faster way of doing this?
MySQL has an ‘extended insert’ syntax, which looks like this:
The only drawback is that this format is not supported by prepared statements, so you have to build the query yourself, which means taking the usual steps to avoid SQL injection problems.