mSQL functionsmSQL
These functions allow you to access mSQL database servers. In
order to have these functions available, you must compile php
with msql support by using the
option. The default
location is /usr/local/Hughes.
More information about mSQL can be found at &url.msql;.
msqlSend mSQL queryDescriptionint msqlstring databasestring queryint link_identifier
Returns a positive mSQL query identifier to the query result, or
&false; on error.
msql selects a database and executes a query
on it. If the optional link identifier isn't specified, the
function will try to find an open link to the mSQL server and if
no such link is found it'll try to create one as if
msql_connect was called with no arguments
(see msql_connect).
msql_affected_rowsReturns number of affected rowsDescriptionint msql_affected_rowsint query_identifier
Returns number of affected ("touched") rows by a specific query
(i.e. the number of rows returned by a SELECT, the number of rows
modified by an update, or the number of rows removed by a
delete).
See also: msql_query.
msql_closeClose mSQL connectionDescriptionint msql_closeint link_identifier
Returns &true; on success, &false; on error.
msql_close closes the link to a mSQL
database that's associated with the specified link identifier.
If the link identifier isn't specified, the last opened link is
assumed.
Note that this isn't usually necessary, as non-persistent open
links are automatically closed at the end of the script's
execution.
msql_close will not close persistent links
generated by msql_pconnect.
See also: msql_connect and
msql_pconnect.
msql_connectOpen mSQL connectionDescriptionint msql_connectstring
hostnamestring
hostname:portstring
usernamestring
password
Returns a positive mSQL link identifier on success, or &false; on
error.
msql_connect establishes a connection to a
mSQL server. The hostname argument is optional, and if it's
missing, localhost is assumed.
In case a second call is made to
msql_connect with the same arguments, no new
link will be established, but instead, the link identifier of the
already opened link will be returned.
The link to the server will be closed as soon as the execution of
the script ends, unless it's closed earlier by explicitly calling
msql_close.
See also msql_pconnect,
msql_close.
msql_create_dbCreate mSQL databaseDescriptionint msql_create_dbstring database nameint
link_identifier
msql_create_db() attempts to create a new database on the server
associated with the specified link identifier.
See also: msql_drop_db.
msql_createdbCreate mSQL databaseDescriptionint msql_createdbstring database nameint
link_identifier
Identical to msql_create_db.
msql_data_seekMove internal row pointerDescriptionint msql_data_seekint query_identifierint row_number
Returns &true; on success, &false; on failure.
msql_data_seek moves the internal row
pointer of the mSQL result associated with the specified query
identifier to pointer to the specifyed row number. The next call
to msql_fetch_row would return that
row.
See also: msql_fetch_row.
msql_dbnameGet current mSQL database nameDescriptionstring msql_dbnameint query_identifierint imsql_dbname returns the database name stored
in position i of the result pointer
returned from the msql_listdbs function. The
msql_numrows function can be used to
determine how many database names are available.
msql_drop_dbDrop (delete) mSQL databaseDescriptionint msql_drop_dbstring database_nameint link_identifier
Returns &true; on success, &false; on failure.
msql_drop_db attempts to drop (remove) an
entire database from the server associated with the specified
link identifier.
See also: msql_create_db.
msql_dropdbDrop (delete) mSQL databaseDescription
See msql_drop_db.
msql_errorReturns error message of last msql callDescriptionstring msql_error
Errors coming back from the mSQL database backend no longer
issue warnings. Instead, use these functions to retrieve the
error string.
msql_fetch_arrayFetch row as arrayDescriptionint msql_fetch_arrayint query_identifierint
result_type
Returns an array that corresponds to the fetched row, or &false; if
there are no more rows.
msql_fetch_array is an extended version of
msql_fetch_row. In addition to storing the
data in the numeric indices of the result array, it also stores
the data in associative indices, using the field names as keys.
The second optional argument result_type
in msql_fetch_array is a constant and can
take the following values: MSQL_ASSOC, MSQL_NUM, and MYSQL_BOTH.
Be careful if you are retrieving results from a query that may
return a record that contains only one field that has a value of
0 (or an empty string, or &null;).
An important thing to note is that using
msql_fetch_array is NOT significantly slower
than using msql_fetch_row, while it provides
a significant added value.
For further details, also see
msql_fetch_row.
msql_fetch_fieldGet field informationDescriptionobject msql_fetch_fieldint query_identifierint field_offset
Returns an object containing field information
msql_fetch_field can be used in order to
obtain information about fields in a certain query result. If
the field offset isn't specified, the next field that wasn't yet
retreived by msql_fetch_field is retreived.
The properties of the object are:
name - column name
table - name of the table the column belongs to
not_null - 1 if the column cannot be &null;
primary_key - 1 if the column is a primary key
unique - 1 if the column is a unique key
type - the type of the column
See also msql_field_seek.
msql_fetch_objectFetch row as objectDescriptionint msql_fetch_objectint query_identifierint
result_type
Returns an object with properties that correspond to the fetched
row, or &false; if there are no more rows.
msql_fetch_object is similar to
msql_fetch_array, with one difference - an
object is returned, instead of an array. Indirectly, that means
that you can only access the data by the field names, and not by
their offsets (numbers are illegal property names).
The optional second argument result_type
in msql_fetch_array is a constant and can
take the following values: MSQL_ASSOC, MSQL_NUM, and MSQL_BOTH.
Speed-wise, the function is identical to
msql_fetch_array, and almost as quick as
msql_fetch_row (the difference is
insignificant).
See also:
msql_fetch_array and
msql_fetch_row.
msql_fetch_rowGet row as enumerated arrayDescriptionarray msql_fetch_rowint query_identifier
Returns an array that corresponds to the fetched row, or &false; if
there are no more rows.
msql_fetch_row fetches one row of data from
the result associated with the specified query identifier. The
row is returned as an array. Each result column is stored in an
array offset, starting at offset 0.
Subsequent call to msql_fetch_row would
return the next row in the result set, or &false; if there are no
more rows.
See also: msql_fetch_array,
msql_fetch_object,
msql_data_seek, and
msql_result.
msql_fieldnameGet field nameDescriptionstring msql_fieldnameint query_identifierint fieldmsql_fieldname returns the name of the
specified field. query_identifier is the
query identifier, and field is the field
index. msql_fieldname($result, 2); will
return the name of the second field in the result associated with
the result identifier.
msql_field_seekSet field offsetDescriptionint msql_field_seekint query_identifierint field_offset
Seeks to the specified field offset. If the next call to
msql_fetch_field won't include a field
offset, this field would be returned.
See also: msql_fetch_field.
msql_fieldtableGet table name for fieldDescriptionint msql_fieldtableint query_identifierint field
Returns the name of the table field was
fetched from.
msql_fieldtypeGet field typeDescriptionstring msql_fieldtypeint query_identifierint imsql_fieldtype is similar to the
msql_fieldname function. The arguments are
identical, but the field type is returned. This will be one of
"int", "char" or "real".
msql_fieldflagsGet field flagsDescriptionstring msql_fieldflagsint query_identifierint imsql_fieldflags returns the field flags of
the specified field. Currently this is either, "not &null;",
"primary key", a combination of the two or "" (an empty string).
msql_fieldlenGet field lengthDescriptionint msql_fieldlenint query_identifierint imsql_fieldlen returns the length of the
specified field.
msql_free_resultFree result memoryDescriptionint msql_free_resultint query_identifiermsql_free_result frees the memory associated
with query_identifier. When PHP completes a
request, this memory is freed automatically, so you only need to
call this function when you want to make sure you don't use too
much memory while the script is running.
msql_freeresultFree result memoryDescriptionSee msql_free_resultmsql_list_fieldsList result fieldsDescriptionint msql_list_fieldsstring databasestring tablenamemsql_list_fields retrieves information about
the given tablename. Arguments are the database name and the
table name. A result pointer is returned which can be used with
msql_fieldflags,
msql_fieldlen,
msql_fieldname, and
msql_fieldtype. A query identifier is a
positive integer. The function returns -1 if a
error occurs. A string describing the error will be placed in
$phperrmsg, and unless the function was called
as @msql_list_fields() then this error string
will also be printed out.
See also msql_error.
msql_listfieldsList result fieldsDescription
See msql_list_fields.
msql_list_dbsList mSQL databases on serverDescriptionint msql_list_dbsmsql_list_dbs will return a result pointer
containing the databases available from the current msql
daemon. Use the msql_dbname function to
traverse this result pointer.
msql_listdbsList mSQL databases on serverDescription
See msql_list_dbs.
msql_list_tablesList tables in an mSQL databaseDescriptionint msql_list_tablesstring databasemsql_list_tables takes a database name and
result pointer much like the msql
function. The msql_tablename function should
be used to extract the actual table names from the result
pointer.
msql_listtablesList tables in an mSQL databaseDescription
See msql_list_tables.
msql_num_fieldsGet number of fields in resultDescriptionint msql_num_fieldsint query_identifiermsql_num_fields returns the number of fields
in a result set.
See also: msql,
msql_query,
msql_fetch_field, and
msql_num_rows.
msql_num_rowsGet number of rows in resultDescriptionint msql_num_rowsint query_identifiermsql_num_rows returns the number of rows in
a result set.
See also: msql,
msql_query, and
msql_fetch_row.
msql_numfieldsGet number of fields in resultDescriptionint msql_numfieldsint query_identifier
Identical to msql_num_fields.
msql_numrowsGet number of rows in resultDescriptionint msql_numrows
Identical to msql_num_rows.
msql_pconnectOpen persistent mSQL connectionDescriptionint msql_pconnectstring
hostnamestring
hostname:portstring
usernamestring
password
Returns a positive mSQL persistent link identifier on success, or
&false; on error.
msql_pconnect acts very much like
msql_connect with two major differences.
First, when connecting, the function would first try to
find a (persistent) link that's already open with the same host.
If one is found, an identifier for it will be returned instead of
opening a new connection.
Second, the connection to the SQL server will not be closed when
the execution of the script ends. Instead, the link will remain
open for future use (msql_close will not
close links established by msql_pconnect).
This type of links is therefore called 'persistent'.
msql_querySend mSQL queryDescriptionint msql_querystring queryint link_identifiermsql_query sends a query to the currently
active database on the server that's associated with the
specified link identifier. If the link identifier isn't
specified, the last opened link is assumed. If no link is open,
the function tries to establish a link as if
msql_connect was called, and use it.
Returns a positive mSQL query identifier on success, or &false; on
error.
See also: msql,
msql_select_db, and
msql_connect.
msql_regcase
Make regular expression for case insensitive match
DescriptionSee sql_regcase.
msql_resultGet result dataDescriptionint msql_resultint query_identifierint imixed field
Returns the contents of the cell at the row and offset in the
specified mSQL result set.
msql_result returns the contents of one cell
from a mSQL result set. The field argument can be the field's
offset, or the field's name, or the field's table dot field's
name (fieldname.tablename). If the column name has been aliased
('select foo as bar from ...'), use the alias instead of the
column name.
When working on large result sets, you should consider using one
of the functions that fetch an entire row (specified below). As
these functions return the contents of multiple cells in one
function call, they're MUCH quicker than
msql_result. Also, note that specifying a
numeric offset for the field argument is much quicker than
specifying a fieldname or tablename.fieldname argument.
Recommended high-performance alternatives:
msql_fetch_row,
msql_fetch_array, and
msql_fetch_object.
msql_select_dbSelect mSQL databaseDescriptionint msql_select_dbstring database_nameint link_identifier
Returns &true; on success, &false; on error.
msql_select_db sets the current active
database on the server that's associated with the specified link
identifier. If no link identifier is specified, the last opened
link is assumed. If no link is open, the function will try to
establish a link as if msql_connect was
called, and use it.
Every subsequent call to msql_query will be
made on the active database.
See also: msql_connect,
msql_pconnect, and
msql_query.
msql_selectdbSelect mSQL databaseDescriptionSee msql_select_db.
msql_tablenameGet table name of fieldDescriptionstring msql_tablenameint query_identifierint fieldmsql_tablename takes a result pointer
returned by the msql_list_tables function as
well as an integer index and returns the name of a table. The
msql_numrows function may be used to
determine the number of tables in the result pointer.
msql_tablename example
<?php
msql_connect ("localhost");
$result = msql_list_tables ("wisconsin");
$i = 0;
while ($i < msql_numrows ($result)) {
$tb_names[$i] = msql_tablename ($result, $i);
echo $tb_names[$i] . "<BR>";
$i++;
}
?>