Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > sql_insertq

sql_insertq

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:

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

Example

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:

  1. $id_article = sql_insertq("spip_articles", $champs);
  2. // check that the server doesn't return an error
  3. if ($id_article > 0 AND $GLOBALS['visiteur_session']['id_auteur']) {
  4. sql_insertq('spip_auteurs_articles', array(
  5. 'id_auteur' => $GLOBALS['visiteur_session']['id_auteur'],
  6. 'id_article' => $id_article));
  7. }

Download

  • Author :
  • Published :
  • Updated : 12/05/17
  • Translations : English, français