Coding with SPIP 2.1
SPIP 2.1 Technical Documentation

> > > > sql_serveur

sql_serveur

The sql_serveur() function is used to both connect to the database server if that has not yet already been done, and to obtain the real name of the function that will be executed for a requested transaction. This function is called transparently by means of aliases. It is therefore normally not a useful operation to employ it directly.

sql_serveur() accepts three parameters, with only the first being critical:

  1. $ins_sql is the name of the function requested from amongst the list of functions that the API understands, such as "select", "update", "updateq"... When left deliberately empty, it is then simply requesting that a connection be made to the database server if such has not already been done.
  2. $serveur,
  3. $continue defines what should happen whenever the SQL API instruction is not found by the requested database manager. Set by default to false, the system returns a fatal error, but it is possible to continue programme execution by setting this parameter’s value to be true.

This function is typically used as below:

  1. // calculate the function name
  2. $f = sql_serveur('select');
  3. // execution of the function as per the determined API
  4. $f($arg1, $arg2, ... );

Download

If you are requesting the select instruction in the instruction set determined for MySQL and existing in the ecrire/req/mysql.php file, then the $f variable will equal spip_mysql_select. Correlation between the instructions and the function is defined in that same file with a global variable: spip_mysql_functions_1 (MySQL is the type of server, 1 is the version of the instruction set).

Using aliases to make things simple

Practically all of the sql_* API functions are aliases which that calculate a function using sql_serveur and then execute it. In this way, calling the sql_select function performs (more or less) exactly the same operation as the previous code. It is these instructions that ought to be used:

  1. sql_select($arg1, $arg2, ...);
  • Author :
  • Published :
  • Updated : 02/06/10
  • Translations : English, français