For example:
dl("sql_relay.so"); $s=sqlrc_alloc("adasz",8000,"","user1","password1",0,1); sqlrc_sendQuery($s,"select table_name from user_tables"); sqlrc_endSession($s); for ($i=0; $i<sqlrc_rowCount($s); $i++) { printf("%s\n",sqlrc_getField($s,$i,"table_name")); } sqlrc_free($s);
An alternative to running dl(sql_relay.so) is to put a line like:
extension=sql_relay.so
In your php.ini file. Doing this will improve performance as the library isn't loaded and unloaded each time a script runs, but only once when the web-server is started.
int sqlrc_alloc(string server, int port, string socket,
string user, string password,
int retrytime, int tries)
Initiates a connection to "server" on "port" or to unix socket "socket" on the local machine and authenticates with "user" and "password". Failed connections will be retried for "tries" times on interval "retrytime" or on for a default number of times on a default interval if left unspecified.
void sqlrc_free(int sqlrcref)
Disconnects and terminates the session if it hasn't been terminated already.
void sqlrc_setResultSetBufferSize(int sqlrcref, int rows)
Sets the number of rows of the result set to buffer at a time. 0 (the default) means buffer the entire result set.
int sqlrc_getResultSetBufferSize(int sqlrcref)
Returns the number of result set rows that will be buffered at a time or 0 for the entire result set.
int sqlrc_ping(int sqlrcref)
Returns 1 if the database is up and 0 if it's down.
string sqlrc_identify(int sqlrcref)
Returns the type of database: oracle7, oracle8, postgresql, mysql, etc.
void sqlrc_cacheOn(int sqlrcref)
Sets query caching on. Future queries will be cached to local files, the names of which can be retrieved using getCacheFileName() after each query is sent. A default time-to-live of 10 minutes is also set.
void sqlrc_setCacheTtl(int sqlrcref, int ttl)
Sets the time-to-live for cached result sets. The sqlr-cachemanger will remove each cached result set "ttl" seconds after it's created.
void sqlrc_cacheOn(int sqlrcref)
Sets query caching off.
If you don't need to use substitution or bind variables in your queries, use these two methods.
int sqlrc_sendQuery(int sqlrcref, string query)
sends "query" and gets a return set. Returns TRUE on success and FALSE on failure.
int sqlrc_sendFileQuery(int sqlrcref, string path, string filename)
Sends the query in file "path"/"filename" and gets a return set. Returns TRUE on success and FALSE on failure.
If you need to use substitution or bind variables, in your queries use the following methods. See the API documentation for more information about substitution and bind variables.
int sqlrc_prepareQuery(int sqlrcref, string query)
Prepare to execute "query".
int sqlrc_prepareFileQuery(int sqlrcref, string path, string filename)
Prepare to execute the contents of "path"/"filename".
int sqlrc_substitution(int sqlrcref, string variable, string value)
int sqlrc_substitution(int sqlrcref, string variable, long value)
int sqlrc_substitution(int sqlrcref, string variable, double value, short precision, short scale)
Define a substitution variable.
int sqlrc_inputBind(int sqlrcref, string variable, string value)
int sqlrc_inputBind(int sqlrcref, string variable, long value)
int sqlrc_inputBind(int sqlrcref, string variable, double value, short precision, short scale)
Define an input bind variable.
int sqlrc_defineOutputBind(int sqlrcref, string variable, int length)
Define an output bind variable.
void sqlrc_validateBinds(int sqlrcref)
If you are binding to any variables that might not actually be in your query, call this to ensure that the database won't try to bind them unless they really are in the query.
int sqlrc_executeQuery(int sqlrcref)
Execute the query that was previously prepared and bound.
int sqlrc_getOutputBind(int sqlrcref, string variable)
Get the value stored in a previously defined output bind variable.
int sqlrc_openCachedResultSet(int sqlrcref, string filename)
Opens a cached result set as if a query that would have generated it had been executed. Returns TRUE on success and FALSE on failure.
int sqlrc_openCachedResultSetWithOffset(int sqlrcref, string filename,
int offset, int row)
Opens a cached result set and skips to "offset". The "row" parameter tells the method which row that offset corresponds to. Returns 1 on success and 0 on failure. */
void sqlrc_endSession(int sqlrcref)
terminates the session
void sqlrc_suspendSession(int sqlrcref)
Disconnects this client from the current session but leaves the session open so that another client can connect to it using sqlrc_resumeSession().
int sqlrc_resumeSession(int sqlrcref, int port, string socket)
Resumes a session previously left open using sqlrc_suspendSession(). Returns 1 on success and 0 on failure.
int sqlrc_resumeCachedSession(int sqlrcref, int port, string socket,
string cachefilename)
Resumes a session previously left open using sqlrc_suspendSession() and continues caching the result set to "cachefilename". Returns 1 on success and 0 on failure.
int sqlrc_getConnectionPort(int sqlrcref)
Returns the inet port that the client is communicating over. This parameter may be passed to another client for use in the sqlrc_resumeSession() command.
string sqlrc_getConnectionSocket(int sqlrcref)
Returns the unix socket that the client is communicating over. This parameter may be passed to another client for use in the sqlrc_resumeSession() command.
int sqlrc_getCacheFileOffset(int sqlrcref)
Returns the offset in the currently open cache file. This parameter may be used in the openCachedResultSet() method to jump to a particular offset in the file.
int sqlrc_colCount(int sqlrcref)
returns the number of columns in the current return set
int sqlrc_rowCount(int sqlrcref)
returns the number of rows in the current return set
int sqlrc_totalRows(int sqlrcref)
Returns the total number of rows that will be returned in the result set. Not all databases support this call. Don't use it for applications which are designed to be portable across databases. -1 is returned by databases which don't support this option.
int sqlrc_affectedRows(int sqlrcref)
Returns the number of rows that were updated, inserted or deleted by the query. Not all databases support this call. Don't use it for applications which are designed to be portable across databases. -1 is returned by databases which don't support this option.
int sqlrc_firstRowIndex(int sqlrcref)
Returns the index of the first buffered row. This is useful when buffering only part of the result set at a time.
string sqlrc_errorMessage(int sqlrcref)
If a query failed and generated an error, the error message is available here. If the query succeeded then this method returns FALSE
string sqlrc_getNullsAsEmptyStrings(int sqlrcref)
Tells the client to return NULL fields and output bind variables as empty strings. This is the default.
string sqlrc_getNullsAsUndefined(int sqlrcref)
Tells the client to return NULL fields and output bind variables as undefined.
string sqlrc_getField(int sqlrcref, int row, int col)
returns a string with value of the specified row and column
array sqlrc_getRow(int sqlrcref, int row)
returns an indexed array of the values of the specified row
array sqlrc_getRowAssoc(int sqlrcref, int row)
returns an associative array of the values of the specified row
array sqlrc_getColumnNames(int sqlrcref)
returns the array of the column names of the current return set
string sqlrc_getColumnName(int sqlrcref, int col)
returns the name of the specified column
string sqlrc_getColumnType(int sqlrcref, string col)
string sqlrc_getColumnType(int sqlrcref, int col)
returns the type of the specified column
int sqlrc_getColumnLength(int sqlrcref, string col)
int sqlrc_getColumnLength(int sqlrcref, int col)
returns the length of the specified column.
int sqlrc_getLongest(int sqlrcref, string col)
int sqlrc_getLongest(int sqlrcref, int col)
Returns the length of the longest field in the specified column.
void sqlrc_debugOn(int sqlrcref)
Causes verbose debugging information to be sent to standard output. Another way to do this is to start a query with "-- debug\n".
void sqlrc_debugOff(int sqlrcref)
turns debugging off
int sqlrc_getDebug(int sqlrcref)
returns FALSE if debugging is off and TRUE if debugging is on
Adam Kropielnicki
adasz@wp.pl