cubrid_query

설명

cubrid_query 함수는 conn_identifier와 관련된 데이터베이스 서버에 하나의 질의를 보낸다. 여러 개의 질의를 보낼 수는 없다.

SELECT 문을 실행하여 얼마나 많은 행이 반환되는지 알기 위해서 cubrid_num_rows()를 호출하거나, DELETE, INSERT, REPLACE, UPDATE 문에 영향받는 행의 개수를 알기 위해서 cubrid_affected_rows()를 호출할 때 cubrid_query 함수가 반환하는 결과 식별자를 사용한다.

구문

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

리턴 값
예제

<?php

// 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'",

cubrid_real_escape_string($firstname),

cubrid_real_escape_string($lastname));

 

// 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() . "\n";

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

    die($message);

}

 

// 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

cubrid_free_result($result);

?>

관련 항목