On the note of arrays… Building large MSQL inserts with php, the easy way

  • $cols[0] = “title”;
  • $vals[0] = “”CodeWord: Apoalyptik””;
  • $cols[1] = “url”;
  • $vals[1] = “”http://blog.apokalyptik.com/””;
  • $cols[2] = “feed_url”
  • $vals[2] = “”http://blog.apokalyptik.com/?feed=rss2″”;

$query=”INSERT INTO weblogs (“.implode(“,”, $cols).”) VALUES(“.implode(“,”, $vals).”)”;

One thought on “On the note of arrays… Building large MSQL inserts with php, the easy way

  1. I'm not 100% certain that this code example actually works.

    1 problem is curly quotes. The other is that you're NOT dealing with single quotes around data values but the idea is excellent and here: http://us3.php.net/manual/en/function.implode.php

    is a base version of implode_with_keys which fixes it and is now part of base.php for Oookles and I modified to call mysql_real_escape_string

    Thank you though. Most helpful.

Leave a Reply to J. Scott JohnsonCancel reply