Product Documentation

FairCom SQL for PHP

Previous Topic

Next Topic

ctsql_query

Sends a query to FairCom DB SQL.

Declaration

resource ctsql_query ( string query [, resource connectionID])

Description

ctsql_query() sends a query to the currently active database on the server that’s associated with the specified connection identifier. If connectionID isn’t specified, the last used link is assumed. The query result is buffered. The buffer size is controlled trough the ctsql.rowsperfetch runtime configuration value. The rows in the buffer are updated when one of the ctsql_fetch..() functions reaches the end of the buffer.

Note: The query string should not end with a semicolon.

Only for SELECT statements ctsql_query() returns a queryID or FALSE if the query was not executed correctly. For other type of FairCom DB SQL statements, ctsql_query() returns TRUE on success and FALSE on error. A non-FALSE return value means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It is perfectly possible for a query to succeed but affect no rows or return no rows.

Assuming the query succeeds, you can call ctsql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

Only for SELECT, ctsql_query() returns a new result identifier which you then pass to ctsql_fetch_array() and other functions dealing with result tables. When you are finished with the result set, you then free the resources associated with it by calling ctsql_free_result(). This memory is also automatically freed at the end of the script’s execution.

See also

ctsql_affected_rows(), ctsql_free_result(), ctsql_fetch_array(), ctsql_fetch_row(), ctsql_fetch_assoc(), ctsql_connect().

TOCIndex