П О Р Т А Л                            
С Е Т Е В Ы Х                          
П Р О Е К Т О В                        
  
Поиск по сайту:
                                                 
Главная

О проекте

Web-мастеру
     HTML & JavaScript
     SSI
     Perl
     PHP
     XML & XSLT
     Unix Shell

MySQL

Безопасность

Хостинг

Другое








Самое читаемое:

Учебник PHP - "Для Чайника".
Просмотров 3408 раз(а).

Иллюстрированный самоучитель по созданию сайтов.
Просмотров 5958 раз(а).

Учебник HTML.
Просмотров 3202 раз(а).

Руководство по PHP5.
Просмотров 5418 раз(а).

Хостинг через призму DNS.
Просмотров 4018 раз(а).

Подборка текстов стандартных документов.
Просмотров 55709 раз(а).

Учебник PHP - Самоучитель
Просмотров 2995 раз(а).

Документация на MySQL (учебник & справочное руководство)
Просмотров 4569 раз(а).

Внешние атаки...
Просмотров 3732 раз(а).

Учебник PHP.
Просмотров 2767 раз(а).

SSI в примерах.
Просмотров 37384 раз(а).



 
 
| Добавить в избранное | Сделать стартовой | Помощь





Руководство по PHP
Пред. След.

db2_bind_param

(PECL)

db2_bind_param --  Binds a PHP variable to an SQL statement parameter

Описание

bool db2_bind_param ( resource stmt, int parameter-number, string variable-name [, int parameter-type [, int data-type [, int precision [, int scale]]]] )

Binds a PHP variable to an SQL statement parameter in a statement resource returned by db2_prepare(). This function gives you more control over the parameter type, data type, precision, and scale for the parameter than simply passing the variable as part of the optional input array to db2_execute().

Список параметров

stmt

A prepared statement returned from db2_prepare().

parameter-number

Specifies the 1-indexed position of the parameter in the prepared statement.

variable-name

A string specifying the name of the PHP variable to bind to the parameter specified by parameter-number.

parameter-type

A constant specifying whether the PHP variable should be bound to the SQL parameter as an input parameter (DB2_PARAM_IN), an output parameter (DB2_PARAM_OUT), or as a parameter that accepts input and returns output (DB2_PARAM_INOUT).

data-type

A constant specifying the SQL data type that the PHP variable should be bound as: one of DB2_BINARY, DB2_CHAR, DB2_DOUBLE, or DB2_LONG .

precision

Specifies the precision with which the variable should be bound to the database.

scale

Specifies the scale with which the variable should be bound to the database.

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Примеры

Пример 1. Binding PHP variables to a prepared statement

The SQL statement in the following example uses two input parameters in the WHERE clause. We call db2_bind_param() to bind two PHP variables to the corresponding SQL parameters. Notice that the PHP variables do not have to be declared or assigned before the call to db2_bind_param(); in the example, $lower_limit is assigned a value before the call to db2_bind_param(), but $upper_limit is assigned a value after the call to db2_bind_param(). The variables must be bound and, for parameters that accept input, must have any value assigned, before calling db2_execute().

<?php

$sql
= 'SELECT name, breed, weight FROM animals
    WHERE weight > ? AND weight < ?'
;
$conn = db2_connect($database, $user, $password);
$stmt = db2_prepare($conn, $sql);

// We can declare the variable before calling db2_bind_param()
$lower_limit = 1;

db2_bind_param($stmt, 1, "lower_limit", DB2_PARAM_IN);
db2_bind_param($stmt, 2, "upper_limit", DB2_PARAM_IN);

// We can also declare the variable after calling db2_bind_param()
$upper_limit = 15.0;

if (
db2_execute($stmt)) {
    while (
$row = db2_fetch_array($stmt)) {
        print
"{$row[0]}, {$row[1]}, {$row[2]}\n";    
    }
}
?>

Результат выполнения данного примера:

Pook, cat, 3.2
Rickety Ride, goat, 9.7
Peaches, dog, 12.3

Пример 2. Calling stored procedures with IN and OUT parameters

The stored procedure match_animal in the following example accepts three different parameters:

  1. an input (IN) parameter that accepts the name of the first animal as input

  2. an input-output (INOUT) parameter that accepts the name of the second animal as input and returns the string TRUE if an animal in the database matches that name

  3. an output (OUT) parameter that returns the sum of the weight of the two identified animals

In addition, the stored procedure returns a result set consisting of the animals listed in alphabetic order starting at the animal corresponding to the input value of the first parameter and ending at the animal corresponding to the input value of the second parameter.

<?php

$sql
= 'CALL match_animal(?, ?, ?)';
$conn = db2_connect($database, $user, $password);
$stmt = db2_prepare($conn, $sql);

$name = "Peaches";
$second_name = "Rickety Ride";
db2_bind_param($stmt, 1, "name", DB2_PARAM_IN);
db2_bind_param($stmt, 2, "second_name", DB2_PARAM_INOUT);
db2_bind_param($stmt, 3, "weight", DB2_PARAM_OUT);

print
"Values of bound parameters _before_ CALL:\n";
print
"  1: {$name} 2: {$second_name} 3: {$weight}\n\n";

if (
db2_execute($stmt)) {
    print
"Values of bound parameters _after_ CALL:\n";
    print
"  1: {$name} 2: {$second_name} 3: {$weight}\n\n";

    print
"Results:\n";
    while (
$row = db2_fetch_array($stmt)) {
        print
"  {$row[0]}, {$row[1]}, {$row[2]}\n";    
    }
}
?>

Результат выполнения данного примера:

Values of bound parameters _before_ CALL:
  1: Peaches 2: Rickety Ride 3:

Values of bound parameters _after_ CALL:
  1: Peaches 2: TRUE 3: 22

Results:
  Peaches, dog, 12.3
  Pook, cat, 3.2
  Rickety Ride, goat, 9.7

Смотрите также

db2_execute()
db2_prepare()



Если Вы не нашли что искали, то рекомендую воспользоваться поиском по сайту:
 





Copyright © 2005-2016 Project.Net.Ru