The sql_alter()
function is used to send an ALTER
type SQL command to the database server to modify the structure of the database.
The function accepts 3 parameters:
-
$q
is the query string (without the term "ALTER") to be executed -
$serveur
, -
$option
Note: This function directly assumes an SQL formatted command, so it is important to respect the SQL standards. It is possible in future versions of SPIP, that the $q
parameter will accept a more structured table as input in order to simplify porting to other systems.
The function is used as shown in this example:
sql_alter("TABLE table ADD COLUMN column_name INT");
sql_alter("TABLE table ADD column_name INT"); // COLUMN is an optional keyword for this SQL command
sql_alter("TABLE table CHANGE column_name column_name INT DEFAULT '0'");
sql_alter("TABLE table ADD INDEX column_name (column_name)");
sql_alter("TABLE table DROP INDEX column_name");
sql_alter("TABLE table DROP COLUMN column_name");
sql_alter("TABLE table DROP column_name"); // COLUMN is an optional keyword for this command
sql_alter("TABLE spip_tradlang RENAME spip_tradlangs");
// You may pass several actions, but be careful about other DBMS ports:
sql_alter("TABLE table DROP column_nameA, DROP column_nameB");
The sql_alter()
function is particularly used during updates for plugins in the {plugin_name}_upgrade()
functions for the various plugins you may have installed.