Previous section To contents Next section

14.13 Mysql.mysql

CLASS
Mysql.mysql

DESCRIPTION
Mysql.mysql is a pre-compiled Pike program. It enables access to the Mysql database from within Pike. Mysql.mysql is a part of the Mysql module. Mysql is available from www.tcx.se.

SEE ALSO
Mysql.result and Sql.sql

METHOD
Mysql.mysql.affected_rows

SYNTAX
int affected_rows()

DESCRIPTION
Returns the number of rows affected by the last query.

METHOD
Mysql.mysql.big_query

SYNTAX
object(Mysql.mysql_result) big_query(string q)

DESCRIPTION
Make an SQL query

ARGUMENTS
argument(s)description
string q
The SQL query This function sends an SQL query to the Mysql-server. The result of the query is returned as a Mysql.mysql_result object. Returns 0 if the query didn't return any result (e.g. INSERT or similar).

SEE ALSO
mysql_result

METHOD
Mysql.mysql.binary_data

SYNTAX
int binary_data()

DESCRIPTION
Inform if this version of mysql supports binary data This function returns non-zero if binary data can be reliably stored and retreived with this version of the mysql-module. Usually, there is no problem storing binary data in mysql-tables, but data containing '\0' (NUL) couldn't be fetched with old versions (prior to 3.20.5) of the mysql-library.

METHOD
Mysql.mysql.create

SYNTAX
void create()
void create(string host)
void create(string host,  string database)
void create(string host,  string database,  string user)
void create(string host,  string database,  string user,  string password)

DESCRIPTION
Connects to a Mysql database. To access the Mysql database, you must first connect to it. This is done with the function mysql(). If you give no argument, or give "" as hostname it will connect with a UNIX-domain socket, which is a big performance gain.

METHOD
Mysql.mysql.create_db

SYNTAX
void create_db(string database)

DESCRIPTION
Create a new database

ARGUMENTS
argument(s)description
string database
Name of the database to be created This function creates a new database in the Mysql-server.

SEE ALSO
select_db and drop_db

METHOD
Mysql.mysql.drop_db

SYNTAX
void drop_db(string database)

DESCRIPTION
Drop a database

ARGUMENTS
argument(s)description
string database
Name of database to be dropped This function drops a database from a Mysql-server.

SEE ALSO
create_db and select_db

METHOD
Mysql.mysql.error

SYNTAX
string error()

DESCRIPTION
Returns a string describing the last error from the Mysql-server.

METHOD
Mysql.mysql.host_info

SYNTAX
string host_info()

DESCRIPTION
Give information about the Mysql-server connection This function returns a string describing the connection to the Mysql-server.

SEE ALSO
statistics, server_info and protocol_info

METHOD
Mysql.mysql.insert_id

SYNTAX
int insert_id()

DESCRIPTION
Returns the id of the last INSERT query into a table with an AUTO INCREMENT field.

METHOD
Mysql.mysql.list_dbs

SYNTAX
object(Mysql.mysql_result) list_dbs()
object(Mysql.mysql_result) list_dbs(string wild)

DESCRIPTION
List databases Returns a table containing the names of all databases in the Mysql-server. If an argument is specified, only those matching wild are returned.

SEE ALSO
list_tables, list_fields, list_processes and Mysql.mysql_result

METHOD
Mysql.mysql.list_fields

SYNTAX
array(int|mapping(string:mixed)) list_fields(string table)
array(int|mapping(string:mixed)) list_fields(string table,  string wild)

DESCRIPTION
List all fields. Returns an array of mappings with information about the fields in the specified table. The mappings contain the following entries:

 "name":        string  The name of the field.
 "table":       string  The name of the table.
 "default":     string  The default value for the field.
 "type":        string  The type of the field.
 "length":      int     The length of the field.
 "max_length":  int     The length of the longest element in this field.
 "flags":       multiset(string)        Some flags.
 "decimals":    int     The number of decimalplaces.
The type of the field can be any of: "decimal", "char", "short", "long", "float", "double", "null", "time", "longlong", "int24", "tiny blob", "medium blob", "long blob", "var string", "string" or "unknown". The flags multiset can contain any of "primary_key": This field is part of the primary key for this table. "not_null": This field may not be NULL. "blob": This field is a blob field.

ARGUMENTS
argument(s)description
string table
Name of table to list the fields of
string wild
Wildcard to filter the result with

NOTE
Michael Widenius recomends usage of the following query instead:

 show fields in 'table' like "wild"

SEE ALSO
list_dbs, list_tables, list_processes and fetch_fields

METHOD
Mysql.mysql.list_processes

SYNTAX
object(Mysql.mysql_result) list_processes()

DESCRIPTION
List all processes in the Mysql-server Returns a table containing the names of all processes in the Mysql-server.

SEE ALSO
list_dbs, list_tables, list_fields and Mysql.mysql_result

METHOD
Mysql.mysql.list_tables

SYNTAX
object(Mysql.mysql_result) list_tables()
object(Mysql.mysql_result) list_tables(string wild)

DESCRIPTION
List tables in the current database

ARGUMENTS
argument(s)description
string wild
Wildcard to filter with. Returns a table containing the names of all tables in the current database. If an argument is given, only those matching wild are returned.

SEE ALSO
list_dbs, list_fields, list_processes and Mysql.mysql_result

METHOD
Mysql.mysql.protocol_info

SYNTAX
int protocol_info()

DESCRIPTION
Give the Mysql protocol version This function returns the version number of the protocol the Mysql-server uses.

SEE ALSO
statistics, server_info and host_info

METHOD
Mysql.mysql.reload

SYNTAX
void reload()

DESCRIPTION
Reload security tables This function causes the Mysql-server to reload its access tables.

SEE ALSO
shutdown

METHOD
Mysql.mysql.select_db

SYNTAX
void select_db(string database)

DESCRIPTION
The Mysql-server can hold several databases. You select which one you want to access with this function.

SEE ALSO
create, create_db and drop_db

METHOD
Mysql.mysql.server_info

SYNTAX
string server_info()

DESCRIPTION
Give the version number of the Mysql-server This function returns the version number of the Mysql-server.

SEE ALSO
statistics, host_info and protocol_info

METHOD
Mysql.mysql.shutdown

SYNTAX
void shutdown()

DESCRIPTION
Shutdown the Mysql-server This function shuts down a running Mysql-server. reload

METHOD
Mysql.mysql.statistics

SYNTAX
string statistics()

DESCRIPTION
Some Mysql-server statistics This function returns some server statistics. Example:

int main()
{
  write(mysql()->statistics());
  return(0);
}

SEE ALSO
server_info, host_info and protocol_info

Previous section To contents Next section