Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 | 



cubrid_bind

Description

The cubrid_bind function substitutes a value for a variable of the cubrid_prepare() with parameters, a various types in PHP and corresponding types in SQL. If bind_value_type is not given, string will be the default. The following table shows the types of substitute values:

Support

Bind type

Corresponding SQL type

Supported

STRING

CHAR, VARCHAR

NCHAR

NCHAR, NVARCHAR

BIT

BIT, VARBIT

NUMERIC or NUMBER

SHORT, INT, NUMERIC

FLOAT

FLOAT

DOUBLE

DOUBLE

TIME

TIME

DATE

DATE

TIMESTAMP

TIMESTAMP

OBJECT

OBJECT

BLOB

BLOB

CLOB

CLOB

NULL

NULL

Not supported

SET

SET

MULTISET

MULTISET

SEQUENCE

SEQUENCE

Syntax

bool cubrid_bind(resource $req_identifier,mixed $bind_param, mixed $bind_value[,string $bind_value_type])

  • req_identifier : Request identifier as a result of cubrid_prepare()
  • bind_param : Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name (Note that the name can only contain digit, alphabet, and underscore, and it cannot begin with digit. The name length cannot be longer than 32). For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.
  • bind_ value : Actual value to be bound
  • bind_value_type : Type of the value to be bound. It can be omitted by default. If it is omitted, the type is automatically cast to an appropriate one. However, NCHAR, BLOB/CLOB and BIT types must be passed as arguments.

Note If data is bound to BLOB/CLOB, CUBRID maps the data into PHP stream, which is a unified approach to handle files and sockets in PHP extension. If the actual value to be bound is not stream, CUBRID returns it as string; this string includes the BLOB/CLOB type meta data (Locator) which is a file path and name recorded in an external storage.

Return Value
  • Success : TRUE
  • Failure : FALSE
Example 1

<?php

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

 

$result = cubrid_execute($conn, "SELECT code FROM event WHERE sports='Basketball' and gender='M'");

$row = cubrid_fetch_array($result, CUBRID_ASSOC);

$event_code = $row["code"];

 

cubrid_close_request($result);

 

$game_req = cubrid_prepare($conn, "SELECT athlete_code FROM game WHERE host_year=1992 and event_code=? and nation_code='USA'");

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

cubrid_execute($game_req);

 

printf("--- Dream Team (1992 United States men's Olympic basketball team) --- ");

while ($athlete_code = cubrid_fetch_array($game_req, CUBRID_NUM)) {

    $athlete_req = cubrid_prepare($conn, "SELECT name FROM athlete WHERE code=? AND nation_code='USA' AND event='Basketball' AND gender='M'");

    cubrid_bind($athlete_req, 1, $athlete_code[0], "number");

    cubrid_execute($athlete_req);

    $row = cubrid_fetch_assoc($athlete_req);

    printf("%s ", $row["name"]);

}

cubrid_close_request($game_req);

cubrid_close_request($athlete_req);

cubrid_disconnect($conn);

?>

 

The above example will output:

 

--- Dream Team (1992 United States men's Olympic basketball team) ---

Stockton John

Robinson David

Pippen Scottie

Mullin C.

Malone Karl

Laettner C.

Jordan Michael

Johnson Earvin

Ewing Patrick

Drexler Clyde

Bird Larry

Barkley Charles

Example 2

<?php

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

 

$sql_stmt = <<<EOD

SELECT s.name FROM stadium s, game g

WHERE s.code = g.stadium_code AND g.medal = :medal_type

GROUP BY g.stadium_code ORDER BY count(medal) DESC LIMIT 1;

EOD;

 

$req = cubrid_prepare($conn, $sql_stmt);

printf("%-30s %s ", "Medal Type", "Stadium where most medals were ever won");

 

cubrid_bind($req, ":medal_type", "G");

cubrid_execute($req);

$row = cubrid_fetch_assoc($req);

printf("%-30s %s ", "Gold", $row["name"]);

 

cubrid_bind($req, ":medal_type", "S");

cubrid_execute($req);

$row = cubrid_fetch_assoc($req);

printf("%-30s %s ", "Silver", $row["name"]);

 

cubrid_bind($req, ":medal_type", "B");

cubrid_execute($req);

$row = cubrid_fetch_assoc($req);

printf("%-30s %s ", "Bronze", $row["name"]);

 

cubrid_close_request($req);

cubrid_disconnect($conn);

?>

 

The above example will output:

 

Medal Type                     Stadium where most medals were ever won

Gold                           Olympic Aquatic Centre

Silver                         Olympic Aquatic Centre

Bronze                         Sydney Convention and Exhibition Centre

Example 3

<?php

$con = cubrid_connect("localhost", 33000, "foo");

if ($con) {

    $sql = "INSERT INTO php_cubrid_lob_test(doc_content) VALUES(?)";

    $req = cubrid_prepare($con, $sql);

 

    $fp = fopen("book.txt", "rb");

 

    cubrid_bind($req, 1, $fp, "blob");

    cubrid_execute($req);  

}

?>

Example 4

<?php

$con = cubrid_connect("localhost", 33000, "foo");

if ($con) {

    $sql = "INSERT INTO php_cubrid_lob_test(image) VALUES(?)";

    $req = cubrid_prepare($con, $sql);

 

    cubrid_bind($req, 1, “cubrid_logo.png”, "blob");

    cubrid_execute($req);  

}

?>

See Also