The cubrid_bind() function is used to bind values to a
corresponding named or question mark placeholder in the SQL statement that
was passed to cubrid_prepare(). If
bind_value_type is not given, string will be the
default.
Замечание:
If the type of data to be bound is BLOB/CLOB, CUBRID will try to map the
data as a PHP stream. If the actually bind value type is not stream,
CUBRID will convert it to string, and use it as the full path and file
name of a file on the client filesystem.
The following table shows the types of substitute values.
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 can not
begin with digit. The name length can not 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 for binding.
bind_value_type
A type of the value to bind. (It is omitted by default.
Thus, system internally use string by default. However, you need to
specify the exact type of the value as an argument when they are NCHAR,
BIT, or BLOB/CLOB).
Возвращаемые значения
TRUE, when process is successful.
FALSE, when process is unsuccessful.
Список изменений
Версия
Описание
8.4.0
Added named parameter support; When binding the LOB data type, it can
directly binding the path name of a file.
$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) ---\n"); 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\n", $row["name"]); }
--- 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
$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\n", "Medal Type", "Stadium where most medals were ever won");
Medal Type Stadium where most medals were ever won
Gold Olympic Aquatic Centre
Silver Olympic Aquatic Centre
Bronze Sydney Convention and Exhibition Centre
Пример #3 cubrid_bind() BLOB/CLOB example
<?php $con = cubrid_connect("localhost", 33000, "foo"); if ($con) { $sql = "INSERT INTO php_cubrid_lob_test(doc_content) VALUES(?)"; $req = cubrid_prepare($con, $sql);