The Mini SQL module is a library of routines for communicating with a Mini SQL database. The functions provided by this module mimic the functions provided by the mSQL C API. Please see the mSQL documentation for more information.Outlined below is a description of each of the functions available within the Mini SQL module.
int msqlConnect ( host )
char *hostmsqlConnect() connects to the mSQL server on the specified host. If no host is specified it connects to the local mSQL server.
Example :
$sock = msqlConnect("research.Hughes.com.au"); if ($sock < 0) { echo("ERROR : $ERRMSG\n"); }
msqlConnect ( sock )
int sockmsqlClose() closes a connection made using msqlConnect().
Example :
msqlClose($sock);
int msqlSelectDB ( sock , db )
int sock
char *dbmsqlSelectDB() tells the mSQL server which database you wish to use.
Example :
if (msqlSelectDB($sock,"my_db") < 0) { echo("ERROR : $ERRMSG\n"); }
int msqlQuery ( sock , query )
int sock
char *querymsqlQuery() submits a query to the mSQL server connected to the specified socket.
Example :
if (msqlQuery($sock, "select * from foo") < 0) { echo("ERROR : $ERRMSG\n"); }
msqlStoreResult ( )
msqlStoreResult() stores any data that was a result of the previous query.
Example :
$res = msqlStoreResult();
msqlFreeResult ( res )
int resmsqlFreeResult() frees any memory allocated to the specified result.
Example :
msqlFreeResult($res);
msqlFetchRow ( res )
int res;msqlFetchRow() returns a single row of the data stored in the specified result.
Example :
$row = msqlFetchRow($res); if ( # $row == 0) { echo("ERROR : $ERRMSG\n"); } else { echo("Field 0 is $row[0]\n"); }
msqlDataSeek ( res , location )
int res
int locationmsqlDataSeek() allows you to move the data pointer within the result table. Specifying a location of 0 will rewind the result. The next call to msqlFetchRow() will return the first row of the result table again.
Example :
msqlDataSeek( $res, 0);
msqlListDBs ( sock )
int sockmsqlListDBs() returns an array of the names of the databases available on the specified server
Example :
$dbs = msqlListDBs($sock); $index = 0; while ($index < # $dbs) { printf("Database = %s\n", $dbs[$index]); $index = $index + 1; }
msqlListTables ( sock , db )
int sock
char *dbmsqlListTables() returns am array of the names of all the tables available in the current database of the specified server
Example :
$tabls = msqlListTables($sock); $index = 0; while ($index < # $tabls) { printf("Table = %s\n", $tabls[$index]); $index = $index + 1; }
msqlInitFieldList ( sock , db , table )
int sock
char *db
char *tablemsqlInitFieldList() generates an internal result handle containing details of all the fields in the specified table of the specified database. The result handle is used in conjunction with the functions below to access the field structure information. Note that the result handle is held as a static variable inside the mSQL module and further calls to msqlInitFieldList() will free the result.
msqlListField ( )
msqlListField() returns an array of information about a single field of the current field list result that was generated using msqlInitFieldList(). The elements of the array contain the following information.
Element Description 0 Field Name 1 Table Type 2 Type 3 Lenght 4 Flags Example :
$res = msqlInitFieldList($sock,"my_db","my_table"); $field = msqlListField($res); while( # $res > 0) { echo("Name $field[0]\n"); $field = msqlListField($res); }
msqlFieldSeek ( res , location )
int res
int locationmsqlFieldSeek() acts upon the result of a call to msqlInitFieldList() in the same way msqlDataSeek() acts upon the result of a call to msqlStoreResult(). It allows you to move the internal result pointer to the specified location.
int msqlNumRows ( res )
int resmsqlNumRows() returns the number of rows contained in the result handle res.
Example :
msqlQuery($sock, "select * from foo"); $res = msqlStoreResult(); printf("There are %d rows in foo\n", msqlNumRows($res);
msqlEncode ( string )
char *stringmsqlEncode() is passed a string value that may contain characters that can cause errors in mSQL query strings (such as the ' character in text values). It returns a modified version of the string with all such characters escaped.
Example :
$name = "O'Reilly"; $newName = msqlEscape($name);