Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.4.0 |  CUBRID 8.4.1 | 



The cubrid_query function sends a single query to a database server associated with conn_identifier. It cannot send multiple queries.

When you call cubrid_num_rows() to get information on the number of rows returned with the SELECt  statement or call cubrid_affected_rows() to get information on the number of rows affected by DELETE, INSERT, REPLACE, or UPDATE statement, use a result identifier returned by the cubrid_query function.


resource cubrid_query (string $query[, resource $conn_identifier])

  • query : SQL query statement
  • conn_identifier : Specifies the CUBRID connection. If it is not specified, the last connection is used.
Return Value
  • Success : Request identifier
  • No access permission to the table : FALSE
  • Failure : FALSE


// This could be supplied by a user, for example

$firstname = 'fred';

$lastname = 'fox';


$conn = cubrid_connect('localhost', 33000, 'foo');


// Formulate Query

// This is the best way to perform an SQL query

// For more examples, see cubrid_real_escape_string()

$query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'",




// Perform Query

$result = cubrid_query($query);


// Check result

// This shows the actual query sent to CUBRID, and the error. Useful for debugging.

if (!$result) {

    $message = 'Invalid query: ' . cubrid_error() . " ";

    $message .= 'Whole query: ' . $query;



// Use result

// Attempting to print $result won't allow access to information in the resource

// One of the cubrid result functions must be used

// See also cubrid_result(), cubrid_fetch_array(), cubrid_fetch_row(), etc.

while ($row = cubrid_fetch_assoc($result)) {

    echo $row['firstname'];

    echo $row['lastname'];

    echo $row['address'];

    echo $row['age'];



// Free the resources associated with the result set

// This is done automatically at the end of the script



See Also