The sql_insertq() function is used to perform a record insert into the database. Non-numeric values will be filtered using functions modified for each database manager in order to correctly handle apostrophes. When possible, the function returns the identifying number for the inserted primary key.

The function accepts 5 parameters:

  1. $table is the name of the SQL table,
  2. $couples is an array table of (name / value) pairs,
  3. $desc,
  4. $serveur,
  5. $option.

It is used as shown below:

$id = sql_insertq('table', array('column1'=>'value1', 'column2'=>'value2'));


The insert_xx() functions like insert_article() described in ecrire/action/editer_article.php are used to create database inserts for the objects in question, by managing the default values and calling the pre_insertion appropriate pipeline. These functions return the identifier of the created record.

These functions therefore run the sql_insertq() function after the pre_insertion pipeline. If an author is identifiable during the process, then the article is linked to that author:

$id_article = sql_insertq("spip_articles", $champs);
// check that the server doesn't return an error
if ($id_article > 0 AND $GLOBALS['visiteur_session']['id_auteur']) {
	sql_insertq('spip_auteurs_articles', array(
		'id_auteur' => $GLOBALS['visiteur_session']['id_auteur'], 
		'id_article' => $id_article));

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français