Основы PHP
  Что такое PHP?
  Возможности PHP
  Преимущества PHP
  История развития
  Что нового в PHP5?
  «Движок» PHP
  Переход на PHP 5.3
New Переход на PHP 5.6
  Введение в PHP
  Изучение PHP
  Основы CGI
  Синтаксис PHP
  Типы данных PHP
  Переменные в PHP
  Константы PHP
  Выражения PHP
  Операторы PHP
  Конструкции PHP
  Ссылки в PHP
  PHP и ООП
  Безопасность
  Функции PHP
  Функции по категориям
  Функции по алфавиту
  Стандартные функции
  Пользовательские
  PHP и HTTP
  Работа с формами
  PHP и Upload
  PHP и Cookies
  PHP и базы данных
  PHP и MySQL
  Документация MySQL
  Учебники
  Учебники по PHP
  Учебники по MySQL
  Другие учебники
  Уроки PHP
  Введение
  Самые основы
  Управление
  Функции
  Документация
  Математика
  Файлы
  Основы SQL
  Дата и время
  CURL
  Изображения
  Стили
  Безопасность
  Установка
  Проектирование БД
  Регулярные выражения
  Подготовка к работе
  Быстрый старт
  Установка PHP
  Установка MySQL
  Конфигурация PHP
  Download / Скачать
  Скачать Apache
  Скачать PHP
  Скачать PECL
  Скачать PEAR
  Скачать MySQL
  Редакторы PHP
  Полезные утилиты
  Документация
  PHP скрипты
  Скачать скрипты
  Инструменты
  PHP в примерах
  Новости портала
 Главная   »  Функции PHP
 
 
Функции PHP »»» Функции IBM DB2, Cloudscape и Apache Derby

db2_connect

(no version information, might be only in CVS)

db2_connect --  Returns a connection to a database

Описание

resource db2_connect ( string database, string username, string password [, array options] )

Creates a new connection to an IBM DB2 Universal Database, IBM Cloudscape, or Apache Derby database.

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

database

For a cataloged connection to a database, database represents the database alias in the DB2 client catalog.

For an uncataloged connection to a database, database represents a complete connection string in the following format: DRIVER={IBM DB2 ODBC DRIVER};DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;
UID=username;PWD=password;
where the parameters represent the following values:

database

The name of the database.

hostname

The hostname or IP address of the database server.

port

The TCP/IP port on which the database is listening for requests.

username

The username with which you are connecting to the database.

password

The password with which you are connecting to the database.

username

The username with which you are connecting to the database.

For uncataloged connections, you must pass a NULL value or empty string.

password

The password with which you are connecting to the database.

For uncataloged connections, you must pass a NULL value or empty string.

options

An associative array of connection options that affect the behavior of the connection, where valid array keys include:

autocommit

Passing the DB2_AUTOCOMMIT_ON value turns autocommit on for this connection handle.

Passing the DB2_AUTOCOMMIT_OFF value turns autocommit off for this connection handle.

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

Returns a connection handle resource if the connection attempt is successful. If the connection attempt fails, db2_connect() returns FALSE.

Примеры


Пример 1. Creating a cataloged connection

Cataloged connections require you to have previously cataloged the target database through the DB2 Command Line Processor (CLP) or DB2 Configuration Assistant.

<?php
$database 
'SAMPLE';
$user 'db2inst1';
$password 'ibmdb2';

$conn db2_connect($database$user$password);

if (
$conn) {
    echo 
"Connection succeeded.";
    
db2_close($conn);
}
else {
    echo 
"Connection failed.";
}
?>

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

Connection succeeded.

Пример 2. Creating an uncataloged connection

An uncataloged connection enables you to dynamically connect to a database.

<?php
$database 
'SAMPLE';
$user 'db2inst1';
$password 'ibmdb2';
$hostname 'localhost';
$port 50000;

$conn_string "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
  
"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn db2_connect($conn_string'''');

if (
$conn) {
    echo 
"Connection succeeded.";
    
db2_close($conn);
}
else {
    echo 
"Connection failed.";
}
?>

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

Connection succeeded.

Пример 3. Creating a connection with autocommit off by default

Passing an array of options to db2_connect() enables you to modify the default behavior of the connection handle.

<?php
$database 
'SAMPLE';
$user 'db2inst1';
$password 'ibmdb2';
$options = array('autocommit' => DB2_AUTOCOMMIT_OFF);

$conn db2_connect($database$user$password$options);

if (
$conn) {
    echo 
"Connection succeeded.\n";
    if (
db2_autocommit($conn)) {
         echo 
"Autocommit is on.\n";
    }
    else {
         echo 
"Autocommit is off.\n";
    }
    
db2_close($conn);
}
else {
    echo 
"Connection failed.";
}
?>

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

Connection succeeded.

Autocommit is off.

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

db2_close()
db2_pconnect()

 
 
 Функции по алфавиту 
   Содержание   
 Функции по категориям 

Есть еще вопросы или что-то непонятно - добро пожаловать на наш  форум портала PHP.SU 
 

 
Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS