cubrid_execute

Description

The cubrid_execute function executes a given SQL statement. It executes a query by using conn_identifier and SQL and then returns the request identifier created. This is an appropriate way to simply execute a query when parameter binding is not necessary.

This function is also used when executing Prepared Statement with cubrid_prepare and cubrid_bind. In this case, required parameters are req_identifier and option.

The option parameter is used to determine whether to get OID after query execution and whether to execute the query in synchronous or asynchronous mode. CUBRID_INCLUDE_OID and CUBRID_ASYNC (or CUBRID_EXEC_QUERY_ALL if you want to execute multiple SQL statements) can be specified by using a bitwise OR operator ( | ). If not specified, neither of them is selected.

If the flag CUBRID_EXEC_QUERY_ALL is set, a synchronous mode (sync_mode) is used to retrieve query results and in such case the following rules are applied.

If req_identifier is the first argument for the execution of cubrid_prepare(), only CUBRID_ASYNC or CUBRID_EXEC_QUERY_ALL can be used as an option.

Syntax

resource cubrid_execute (resource $conn_identifier, string $SQL [, int $option])

bool cubrid_execute (resource &req_identifier[, int $option])

Return Value
Example

<?php

$conn = cubrid_connect("localhost", 33000, "demodb");

 

$result = cubrid_execute($conn, "SELECT code FROM event WHERE name='100m Butterfly' and gender='M'", CUBRID_ASYNC);

$row = cubrid_fetch_array($result, CUBRID_ASSOC);

$event_code = $row["code"];

 

cubrid_close_request($result);

 

$history_req = cubrid_prepare($conn, "SELECT * FROM history WHERE event_code=?");

cubrid_bind($history_req, 1, $event_code, "number");

cubrid_execute($history_req);

 

printf("%-20s %-9s %-10s %-5s\n", "athlete", "host_year", "score", "unit");

while ($row = cubrid_fetch_array($history_req, CUBRID_ASSOC)) {

    printf("%-20s %-9s %-10s %-5s\n",

        $row["athlete"], $row["host_year"], $row["score"], $row["unit"]);

}

 

cubrid_close_request($history_req);

 

cubrid_disconnect($conn);

?>

 

The above example will output:

 

athlete         host_year score         unit

Phelps Michael  2004      51.25         time

See Also