cubrid_bind
(PECL CUBRID >= 8.3.0)
cubrid_bind — Bind variables to a prepared statement as parameters
Описание
$req_identifier
, int $bind_index
, mixed $bind_value
[, string $bind_value_type
] )
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.
If the type of data to be bound explicitly is ENUM, the $bind_value argument should be the enum element which is in string format.
In CUBRID shard envrioment, the $bind_value_type must be included in the cubrid_bind function.
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 | |
ENUM | ENUM | |
BLOB | BLOB | |
CLOB | CLOB | |
NULL | NULL | |
Not supported | SET | SET |
MULTISET | MULTISET | |
SEQUENCE | SEQUENCE |
Список параметров
-
req_identifier
-
Request identifier as a result of cubrid_prepare().
-
bind_index
-
Location of binding parameters. It starts with 1.
-
bind_value
-
Actual value for binding.
-
bind_value_type
-
A type of the value to bind. (It is omitted by default. Thus, the system internally uses 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.3.1 | Added BLOB/CLOB data types support. |
Примеры
Пример #1 cubrid_bind() example
<?php
$conn = cubrid_connect("localhost", 33000, "demodb", "dba");
$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"]);
}
cubrid_close_request($game_req);
cubrid_close_request($athlete_req);
cubrid_disconnect($conn);
?>
Результат выполнения данного примера:
--- 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
Пример #2 cubrid_bind() BLOB/CLOB example
<?php
$con = cubrid_connect("localhost", 33000, "demodb", "dba", "");
if ($con) {
cubrid_execute($con,"DROP TABLE if exists php_cubrid_lob_test");
cubrid_execute($con,"CREATE TABLE php_cubrid_lob_test (doc_content CLOB)");
$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, "clob");
cubrid_execute($req);
}
?>
Пример #3 cubrid_bind() BLOB/CLOB example
<?php
$con = cubrid_connect("localhost", 33000, "demodb", "dba", "");
if ($con) {
cubrid_execute($con,"DROP TABLE if exists php_cubrid_lob_test");
cubrid_execute($con,"CREATE TABLE php_cubrid_lob_test (image BLOB)");
$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);
}
?>
Смотрите также
- cubrid_execute() - Execute a prepared SQL statement
- cubrid_prepare() - Prepare a SQL statement for execution
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- CUBRID
- cubrid_bind
- cubrid_close_prepare
- cubrid_close_request
- cubrid_col_get
- cubrid_col_size
- cubrid_column_names
- cubrid_column_types
- cubrid_commit
- cubrid_connect_with_url
- cubrid_connect
- cubrid_current_oid
- cubrid_disconnect
- cubrid_drop
- cubrid_error_code_facility
- cubrid_error_code
- cubrid_error_msg
- cubrid_execute
- cubrid_fetch
- cubrid_free_result
- cubrid_get_autocommit
- cubrid_get_charset
- cubrid_get_class_name
- cubrid_get_client_info
- cubrid_get_db_parameter
- cubrid_get_query_timeout
- cubrid_get_server_info
- cubrid_get
- cubrid_insert_id
- cubrid_is_instance
- cubrid_lob_close
- cubrid_lob_export
- cubrid_lob_get
- cubrid_lob_send
- cubrid_lob_size
- cubrid_lob2_bind
- cubrid_lob2_close
- cubrid_lob2_export
- cubrid_lob2_import
- cubrid_lob2_new
- cubrid_lob2_read
- cubrid_lob2_seek64
- cubrid_lob2_seek
- cubrid_lob2_size64
- cubrid_lob2_size
- cubrid_lob2_tell64
- cubrid_lob2_tell
- cubrid_lob2_write
- cubrid_lock_read
- cubrid_lock_write
- cubrid_move_cursor
- cubrid_next_result
- cubrid_num_cols
- cubrid_num_rows
- cubrid_pconnect_with_url
- cubrid_pconnect
- cubrid_prepare
- cubrid_put
- cubrid_rollback
- cubrid_schema
- cubrid_seq_drop
- cubrid_seq_insert
- cubrid_seq_put
- cubrid_set_add
- cubrid_set_autocommit
- cubrid_set_db_parameter
- cubrid_set_drop
- cubrid_set_query_timeout
- cubrid_version
Коментарии
404 Not Found