PHP-Fusion
v.7.01
AP-Fusion
v7.02.05
Pimped-Fusion-AP
v0.09.03
November 25 2024 19:41:47
Авторизация
Логин

Пароль



Вы не зарегистрированы?
Нажмите здесь для регистрации.

Забыли пароль?
Запросите новый здесь.
Мини-чат
Вы должны авторизироваться, чтобы добавить сообщение.

lom
06/04/2018 14:03
Мы рады, ждем девятку. Очень хочется пощупать

Alipapa
27/03/2018 22:16
Всем привет, все неисправности устранили, всё у нас работает

mukaton
30/10/2015 02:37
Не получается ничего скачать. Ошибка Not Found

Alipapa
06/10/2015 23:00
9-я версия php-fusion на подходе, следите за новостями

Alipapa
10/11/2014 11:24
Заметь, я дважды ответил через 3 минуты после вопроса, могли бы уже решить

Последние статьи
· О стабилизаторах нап...
· СМС и Вебмани
· TinyMCE для пользова...
· PCRE (Perl Compatibl...
· PCRE (Perl Compatibl...
Последние активные темы форума
  Темы Просмотров Ответов Последние сообщения
PHP-Fusion 7 Bogatyr - бесп...
Моды, плагины
7742 1 Vveb--ws
08-10-2018 16:47
Php-Fusion v9. Первые впеча...
Вопросы по работе
5028 3 Vveb--ws
25-07-2018 13:46
Появился хэлп по PHP-Fusion...
Вопросы по работе
7190 7 Vveb--ws
25-07-2018 13:42
prestashop&ap-fusion
Вопросы по работе
18311 61 Alipapa
26-08-2014 10:29
Плагин магазина Ap-Shop
Моды, плагины
15372 70 Alipapa
18-08-2014 18:14
TinyMCE
Вопросы по работе
21935 55 Alipapa
27-07-2013 21:57
HTML-5
Моды, плагины
5790 1 Alipapa
15-06-2013 19:47
Мультиязычность в Pimped-Fu...
Ошибки, баги, глюки
6678 4 Papich
16-04-2013 12:39
Pimped-Fusion. Первые впеча...
Ошибки, баги, глюки
23360 127 Alipapa
18-12-2012 10:59
Ищу мод для расстановки код...
Моды, плагины
15626 55 Alipapa
17-09-2012 14:00
Как присоединить файл к лич...
Моды, плагины
8550 3 lom
27-05-2012 18:12
Что мне не нравится в после...
Вопросы по работе
7152 4 Alipapa
27-05-2012 18:08
Проблемы с добавлением кате...
Вопросы по работе
8120 5 Alipapa
27-05-2012 18:06

dbx_query

(PHP 4 >= 4.0.6, PHP 5)

dbx_query -- Send a query and fetch all results (if any)

Description

object dbx_query ( object link_identifier, string sql_statement [, int flags] )

dbx_query() returns an object or 1 on success, and 0 on failure. The result object is returned only if the query given in sql_statement produces a result set (i.e. a SELECT query, even if the result set is empty).

Пример 1. How to handle the returned value

<?php
$link   
= dbx_connect ( DBX_ODBC , "" , "db" , "username" , "password" )
    or die(
"Could not connect" );

$result = dbx_query ( $link , 'SELECT id, parentid, description FROM table' );

if (
is_object ( $result ) ) {
    
// ... do some stuff here, see detailed examples below ...
    // first, print out field names and types
    // then, draw a table filled with the returned field values
} else {
    exit(
"Query failed" );
}

dbx_close ( $link );
?>

The flags parameter is used to control the amount of information that is returned. It may be any combination of the following constants with the bitwise OR operator (|). The DBX_COLNAMES_* flags override the dbx.colnames_case setting from php.ini.

DBX_RESULT_INDEX

It is always set, that is, the returned object has a data property which is a 2 dimensional array indexed numerically. For example, in the expression data[2][3] 2 stands for the row (or record) number and 3 stands for the column (or field) number. The first row and column are indexed at 0.

If DBX_RESULT_ASSOC is also specified, the returning object contains the information related to DBX_RESULT_INFO too, even if it was not specified.

DBX_RESULT_INFO

It provides info about columns, such as field names and field types.

DBX_RESULT_ASSOC

It effects that the field values can be accessed with the respective column names used as keys to the returned object's data property.

Associated results are actually references to the numerically indexed data, so modifying data[0][0] causes that data[0]['field_name_for_first_column'] is modified as well.

DBX_RESULT_UNBUFFERED (PHP 5)

This flag will not create the data property, and the rows property will initially be 0. Use this flag for large datasets, and use dbx_fetch_row() to retrieve the results row by row.

The dbx_fetch_row() function will return rows that are conformant to the flags set with this query. Incidentally, it will also update the rows each time it is called.

DBX_COLNAMES_UNCHANGED (available from PHP 4.3.0)

The case of the returned column names will not be changed.

DBX_COLNAMES_UPPERCASE (available from PHP 4.3.0)

The case of the returned column names will be changed to uppercase.

DBX_COLNAMES_LOWERCASE (available from PHP 4.3.0)

The case of the returned column names will be changed to lowercase.

Note that DBX_RESULT_INDEX is always used, regardless of the actual value of flags parameter. This means that only the following combinations are effective:

  • DBX_RESULT_INDEX

  • DBX_RESULT_INDEX | DBX_RESULT_INFO

  • DBX_RESULT_INDEX | DBX_RESULT_INFO | DBX_RESULT_ASSOC - this is the default, if flags is not specified.

The returned object has four or five properties depending on flags:

handle

It is a valid handle for the connected database, and as such it can be used in module specific functions (if required).

<?php
$result
= dbx_query ( $link , "SELECT id FROM table" );
mysql_field_len ( $result -> handle , 0 );
?>

cols and rows

These contain the number of columns (or fields) and rows (or records) respectively.

<?php
$result
= dbx_query ( $link , 'SELECT id FROM table' );
echo
$result -> rows ; // number of records
echo $result -> cols ; // number of fields
?>

info (optional)

It is returned only if either DBX_RESULT_INFO or DBX_RESULT_ASSOC is specified in the flags parameter. It is a 2 dimensional array, that has two named rows (name and type) to retrieve column information.

Пример 2. lists each field's name and type

<?php
$result
= dbx_query ( $link , 'SELECT id FROM table' ,
                     
DBX_RESULT_INDEX | DBX_RESULT_INFO );

for (
$i = 0 ; $i < $result -> cols ; $i ++ ) {
    echo
$result -> info [ 'name' ][ $i ] . "\n" ;
    echo
$result -> info [ 'type' ][ $i ] . "\n" ;  
}
?>
data

This property contains the actual resulting data, possibly associated with column names as well depending on flags. If DBX_RESULT_ASSOC is set, it is possible to use $result->data[2]["field_name"].

Пример 3. outputs the content of data property into HTML table

<?php
$result
= dbx_query ( $link , 'SELECT id, parentid, description FROM table' );

echo
"<table>\n" ;
foreach (
$result -> data as $row ) {
    echo
"<tr>\n" ;
    foreach (
$row as $field ) {
        echo
"<td>$field</td>" ;
    }
    echo
"</tr>\n" ;
}
echo
"</table>\n" ;
?>

Пример 4. How to handle UNBUFFERED queries

<?php

$result
= dbx_query ( $link , 'SELECT id, parentid, description FROM table' , DBX_RESULT_UNBUFFERED );

echo
"<table>\n" ;
while (
$row = dbx_fetch_row ( $result )) {
    echo
"<tr>\n" ;
    foreach (
$row as $field ) {
        echo
"<td>$field</td>" ;
    }
    echo
"</tr>\n" ;
}
echo
"</table>\n" ;

?>

Замечание: Always refer to the module-specific documentation as well.

Column names for queries on an Oracle database are returned in lowercase.

Смотрите также dbx_escape_string(), dbx_fetch_row() and dbx_connect().

Все функции PHP:
Навигация
· Новости
· Статьи
· Скачать
· Форум
· Ссылки
· Категории новостей
· Обратная связь
· Галерея
· Поиск
· CMS AP-Fusion. Отличия от PHP-Fusion
· Javascript справочник
· Техника
Сейчас на сайте
· Гостей: 23

· Пользователей: 0

· Всего пользователей: 453
· Новый пользователь: ZDA
Информеры
Загрузка файлов  +  -
10,247,026 уникальных посетителей Iceberg by Harly