Ingres DBMS, EDBC, and Enterprise Access Gateways

目录

The Ingres driver for PHP enables you to connect to and query the Ingres DBMS, EDBC, and Enterprise Access Gateways.

Note:

此扩展已被移至 » PECL 资源库且不再与 PHP 捆绑。5.1.0.

安装/配置

目录

需求

To use or build the PHP extension for Ingres you must have a working Ingres client environment. You can download the client software for Ingres from » http://esd.ingres.com/.

安装

» PECL 扩展未与 PHP 捆绑。 安装此 PECL 扩展相关的信息可在手册中标题为 PECL 扩展的安装章节中找到。更多信息如新的发行版本、下载、源文件、 维护人员信息及变更日志等,都在此处: » https://pecl.php.net/package/ingres.

You can download the DLL for this PECL extension from » http://esd.ingres.com/product/drivers/PHP/.

To have these functions available, you must » download and compile this extension, enabling Ingres support using the --with-ingres[=DIR] option, where DIR is the Ingres base directory. If the II_SYSTEM environment variable is not set correctly you may need to use --with-ingres=DIR to specify your Ingres installation directory.

PHP code written for version 2.x and later is not backward-compatible with earlier versions of this PHP extension. However, it is possible to run two incompatible releases within the same PHP environment using the --enable-ingres2 option. This configuration option renames the extension to ingres2, changing function names, configuration settings, and constants. For example, with this option enabled, ingres_connect becomes ingres2_connect.

To use this extension the system environment variable II_SYSTEM must be defined. Linux and UNIX users will also need to define the shared library search path, for example, LD_LIBRARY_PATH. When used with the Apache web server these variables must be set explicitly in the startup script for Apache. In addition, the PassEnv directive is required for the Ingres extension to load the correct shared libraries. For example:

示例 #1 Example usage of PassEnv for Ingres

<IfModule mod_env.c>
    PassEnv II_SYSTEM
    PassEnv LD_LIBRARY_PATH
</IfModule>

Note:

For example configurations for different web servers and operating systems see » http://community.ingres.com/wiki/Ingres_Articles#Ingres_and_Web_Servers.

运行时配置

这些函数的行为受 php.ini 中的设置影响。

名字默认可修改范围更新日志
ingres.allow_persistent"1"PHP_INI_SYSTEMAvailable since ingres 1.0.0
ingres.array_index_start"1"PHP_INI_ALLAvailable since ingres 1.4.0.
ingres.auto"1"PHP_INI_ALLAvailable since ingres 2.0.0.
ingres.blob_segment_length"4096"PHP_INI_ALLAvailable since ingres 1.2.0.
ingres.cursor_mode"0"PHP_INI_ALLAvailable since ingres 1.1.0.
ingres.default_databaseNULLPHP_INI_ALLAvailable since ingres 1.0.0
ingres.default_passwordNULLPHP_INI_ALLAvailable since ingres 1.0.0
ingres.default_userNULLPHP_INI_ALLAvailable since ingres 1.0.0
ingres.describe1PHP_INI_ALLAvailable since ingres 2.1.0
ingres.fetch_buffer_size100PHP_INI_ALLAvailable since ingres 2.1.0
ingres.max_links"-1"PHP_INI_SYSTEMAvailable since ingres 1.0.0
ingres.max_persistent"-1"PHP_INI_SYSTEMAvailable since ingres 1.0.0
ingres.reuse_connection"1"PHP_INI_ALLAvailable since ingres 2.0.0
ingres.scrollable"1"PHP_INI_ALLAvailable since ingres 2.0.0.
ingres.trace"0"PHP_INI_ALLAvailable since ingres 2.0.0.
ingres.trace_connect"0"PHP_INI_ALLAvailable since ingres 1.2.1.
ingres.utf8"1"PHP_INI_ALLAvailable since ingres 2.0.0.

有关 PHP_INI_* 样式的更多详情与定义,见 配置可被设定范围

这是配置指令的简短说明。

ingres.allow_persistent boolean
Specifies whether to allow persistent connections to Ingres

ingres.array_index_start integer
Specifies the start value for an integer key for arrays generated by ingres_fetch_row or ingres_fetch_array. By default ingres.array_index_start is set to 1. If you wish to make the ingres extension behave like other database extensions set this configuration option to 0.

ingres.auto boolean
Enables or disables autocommit emulation. Ingres cannot have multiple cursors open with autocommit enabled. When enabled, the driver emulates autocommit.

ingres.blob_segment_length integer
Specifies the amount of memory to use when reading BLOB data, in bytes

ingres.cursor_mode integer
Specifies the default mode for cursors opened with ingres_prepare(). Valid values are INGRES_CURSOR_UPDATE or INGRES_CURSOR_READONLY.

ingres.default_database string
Specifies the default database name to use when connecting to the database server if no other name is specified. Does not apply in SQL 安全模式.

ingres.default_password string
Specifies the default password to use when connecting to the database server if no other name is specified. Does not apply in SQL 安全模式.

ingres.default_user string
Specifies the default user name to use when connecting to the database server if no other name is specified. Does not apply in SQL 安全模式.

ingres.describe boolean
Enables the use of DESCRIBE INPUT to determine the expected data types for queries that use parameters. Available with Ingres 9.1.0 and later. When disabled, queries that have parameters passed may need to manually describe the types of those parameters using the types parameter in ingres_query.

Note:

Enabling this feature with ingres_query will cause additional communications traffic between this extension and the server. To minimize this additional traffic, use class="function">ingres_prepare and class="function">ingres_execute.

ingres.fetch_buffer_size integer
Specifies the number of pre-fetch rows that ingres_fetch_array, ingres_fetch_object and ingres_fetch_row will try and fetch in one fetch operation.

ingres.max_links integer
Specifies the maximum number of Ingres sessions allowed per process or thread. The number of sessions should not exceed the total number of connected sessions configured within Ingres.

ingres.max_persistent integer
Specifies the maximum number of persistent Ingres sessions allowed per process or thread. The number of sessions should not exceed the total number of connected sessions configured within Ingres.

ingres.reuse_connection boolean
Reuses an existing active connection if connecting to the same database with the same user name

ingres.scrollable boolean
Enables support for scrollable cursors. When fetching CLOB or BLOB data, this should be set to FALSE. Available with Ingres 9.2.0 or later.

ingres.trace boolean
Enables simple tracing using E_NOTICE messages

ingres.trace_connect boolean
Prints E_NOTICE messages during ingres_connect or ingres_pconnect calls

ingres.utf8 boolean
Assumes that strings being passed to National Character column types (NVARCHAR or NCHAR) are using UTF8 encoding and converts them to UTF16 for the server

资源类型

ingres_connect and ingres_pconnect return an Ingres link identifier.

ingres_query and ingres_unbuffered_query return an Ingres result identifier.

预定义常量

下列常量由此扩展定义,且仅在此扩展编译入 PHP 或在运行时动态载入时可用。

INGRES_ASSOC (integer)
Columns are returned into the array having the fieldname as the array index. Used with ingres_fetch_array.

INGRES_NUM (integer)
Columns are returned into the array having a numerical index to the fields. By default this index starts at 1, the first field in the result. To change this value, see ingres.array_index_start. Used with ingres_fetch_array.

INGRES_BOTH (integer)
Columns are returned into the array having both a numerical index and the fieldname as the array index. Used with ingres_fetch_array.

INGRES_EXT_VERSION (string)
Specifies the version of the Ingres Extension. Available since version 1.2.0 of the PECL extension.

INGRES_API_VERSION (integer)
Specifies the version of Ingres OpenAPI that the extension was built against. Available since version 1.2.0 of the PECL extension.

INGRES_CURSOR_READONLY (integer)
Specifies that Ingres cursors should be opened in "readonly" mode. Available since version 1.2.0 of the PECL extension. Used with ingres.cursor_mode.

INGRES_CURSOR_UPDATE (integer)
Specifies that Ingres cursors should be opened "for update." Available since version 1.2.0 of the PECL extension. Used with ingres.cursor_mode.

INGRES_DATE_MULTINATIONAL (integer)
Equivalent to the II_DATE_FORMAT setting of MULTINATIONAL. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_DATE_MULTINATIONAL4 (integer)
Equivalent to the II_DATE_FORMAT setting of MULTINATIONAL4. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_DATE_FINNISH (integer)
Equivalent to the II_DATE_FORMAT setting of FINNISH. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_DATE_ISO (integer)
Equivalent to the II_DATE_FORMAT setting of ISO. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_DATE_ISO4 (integer)
Equivalent to the II_DATE_FORMAT setting of ISO4. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_DATE_GERMAN (integer)
Equivalent to the II_DATE_FORMAT setting of GERMAN. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_DATE_MDY (integer)
Equivalent to the II_DATE_FORMAT setting of MDY. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_DATE_DMY (integer)
Equivalent to the II_DATE_FORMAT setting of DMY. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_DATE_YMD (integer)
Equivalent to the II_DATE_FORMAT setting of YMD. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_MONEY_LEADING (integer)
Specifies the currency character that should be placed at the start of a money value. Equivalent to setting II_MONEY_FORMAT to "L:". Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_MONEY_TRAILING (integer)
Specifies the currency character that should be placed at the end of a money value. Equivalent to setting II_MONEY_FORMAT to "T:". Available since version 1.2.0 of the PECL extension. Used with ingres_connect, ingres_pconnect and ingres_set_environment. See options in ingres_set_environment.

INGRES_STRUCTURE_BTREE (integer)
Specifies the default table or index structure to BTREE when used in combination with the options or index_structure option when connecting. Available since version 1.4.0 of the PECL extension. Used with ingres_connect and ingres_pconnect. See options in ingres_connect.

INGRES_STRUCTURE_CBTREE (integer)
Specifies the default table or index structure to COMPRESSED BTREE when used in combination with the options or index_structure option when connecting. Available since version 1.4.0 of the PECL extension. Used with ingres_connect and ingres_pconnect. See options in ingres_connect.

INGRES_STRUCTURE_HASH (integer)
Specifies the default table or index structure to HASH when used in combination with the options or index_structure option when connecting. Available since version 1.4.0 of the PECL extension. Used with ingres_connect and ingres_pconnect. See options in ingres_connect.

INGRES_STRUCTURE_CHASH (integer)
Specifies the default table or index structure to COMPRESSED HASH when used in combination with the options or index_structure option when connecting. Available since version 1.4.0 of the PECL extension. Used with ingres_connect and ingres_pconnect. See options in ingres_connect.

INGRES_STRUCTURE_HEAP (integer)
Specifies the default table structure to HEAP when used in combination with the options option when connecting. Available since version 1.4.0 of the PECL extension. Used with ingres_connect and ingres_pconnect. See options in ingres_connect.

INGRES_STRUCTURE_CHEAP (integer)
Specifies the default table structure to COMPRESSED HEAP when used in combination with the options option when connecting. Available since version 1.4.0 of the PECL extension. Used with ingres_connect and ingres_pconnect. See options in ingres_connect.

INGRES_STRUCTURE_ISAM (integer)
Specifies the default table or index structure to ISAM when used in combination with the options or index_structure option when connecting. Available since version 1.4.0 of the PECL extension. Used with ingres_connect and ingres_pconnect. See options in ingres_connect.

INGRES_STRUCTURE_CISAM (integer)
Specifies the default table or index structure to COMPRESSED ISAM when used in combination with the options or index_structure option when connecting. Available since version 1.4.0 of the PECL extension. Used with ingres_connect and ingres_pconnect. See options in ingres_connect.

范例

目录

Basic usage

The following simple example shows how to connect to an Ingres database, execute a query, print resulting rows and disconnect from the database.

示例 #1 Simple Ingres Example

<?php
// Connecting, selecting database
$link = ingres_connect("database", "user", "password")
    or die("Could not connect: " . ingres_error($link));
echo "Connected successfully";

// Select from a table that exists in all Ingres databases
$query = "SELECT * FROM iitables";
$result = ingres_query($link,$query) or die("Query failed: " .
ingres_error($link));

// Print results in HTML
// relid - table name
// relowner - table owner
echo "<table>\n";
while ($iitables = ingres_fetch_object($result)) {
    echo "\t<tr>\n";
    echo "\t\t<td>" . $iitables->relid . "</td>\n";
    echo "\t\t<td>" . $iitables->relowner . "</td>\n";
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free results
ingres_free_result($result);

// Commit transaction
ingres_commit($link);

// Closing connection
ingres_close($link);
?>

ingres_autocommit_state

Test if the connection is using autocommit

说明

bool ingres_autocommit_state ( resource $link )

ingres_autocommit_state is called to determine whether the current link has autocommit enabled or not.

参数

link
The connection link identifier

返回值

Returns TRUE if autocommit is enabled or FALSE when autocommit is disabled

参见

  • ingres_autocommit
  • ingres_query

ingres_autocommit

Switch autocommit on or off

说明

bool ingres_autocommit ( resource $link )

ingres_autocommit is called before opening a transaction (before the first call to ingres_query or just after a call to ingres_rollback or ingres_commit) to switch the autocommit mode of the server on or off (when the script begins the autocommit mode is off).

When autocommit mode is on, every query is automatically committed by the server, as if ingres_commit was called after every call to ingres_query. To see if autocommit is enabled use, ingres_autocommit_state.

By default Ingres will rollback any uncommitted transactions at the end of a request. Use this function or ingres_commit to ensure your data is committed to the database.

参数

link
The connection link identifier

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • ingres_autocommit_state
  • ingres_query
  • ingres_rollback
  • ingres_commit

ingres_charset

Returns the installation character set

说明

string ingres_charset ( resource $link )

ingres_charset is called to determine the character set being used by the Ingres client, from II_CHARSETxx (where xx is the installation code).

Note:

You can override the value returned by using the function class="function">putenv. Changing the value of II_CHARSETxx in a running Ingres installation can cause data corruption.

参数

link
The connection link identifier

返回值

Returns a string with the value for II_CHARSETxx or returns NULL if the value could not be determined.

范例

示例 #1 ingres_charset - Get the installation character set

<?php
$link = ingres_connect($database, $user, $password);

echo ingres_charset($link) . "\n";

ingres_close($link);
?>

参见

  • ingres_connect
  • ingres_query

ingres_close

Close an Ingres database connection

说明

bool ingres_close ( resource $link )

ingres_close closes the connection to the Ingres server that is associated with the specified link.

ingres_close is usually unnecessary, as it will not close persistent connections and all non-persistent connections are automatically closed at the end of the script.

参数

link
The connection link identifier

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • ingres_connect
  • ingres_pconnect

ingres_commit

Commit a transaction

说明

bool ingres_commit ( resource $link )

ingres_commit commits the currently open transaction, making all changes made to the database permanent.

This closes the transaction. A new transaction can be opened by sending a query with ingres_query.

You can also have the server commit automatically after every query by calling ingres_autocommit before opening the transaction.

By default Ingres will roll back any uncommitted transactions at the end of a request. Use this function or ingres_autocommit to ensure your that data is committed to the database.

参数

link
The connection link identifier

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • ingres_query
  • ingres_rollback
  • ingres_autocommit

ingres_connect

Open a connection to an Ingres database

说明

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

ingres_connect opens a connection with the given Ingres database.

The connection is closed when the script ends or when ingres_close is called on this link.

参数

If some parameters are missing, ingres_connect uses the values in php.ini for ingres.default_database, ingres.default_user and ingres.default_password.

database
The database name. Must follow the syntax:

[vnode::]dbname[/svr_class]

username
The Ingres user name

password
The password associated with username

options
ingres_connect options

Option name Option type Description Example
date_century_boundary integer The threshold by which a 2-digit year is determined to be in the current century or in the next century. Equivalent to II_DATE_CENTURY_BOUNDARY. 50
group string Specifies the group ID of the user, equivalent to the "-G" flag payroll
role string The role ID of the application. If a role password is required, the parameter value should be specified as "role/password"
effective_user string The ingres user account being impersonated, equivalent to the "-u" flag another_user
dbms_password string The internal database password for the user connecting to Ingres s3cr3t
table_structure string

The default structure for new tables. Valid values for table_structure are:

  • INGRES_STRUCTURE_BTREE
  • INGRES_STRUCTURE_HASH
  • INGRES_STRUCTURE_HEAP
  • INGRES_STRUCTURE_ISAM
  • INGRES_STRUCTURE_CBTREE
  • INGRES_STRUCTURE_CISAM
  • INGRES_STRUCTURE_CHASH
  • INGRES_STRUCTURE_CHEAP
INGRES_STRUCTURE_BTREE
index_structure string

The default structure for new secondary indexes. Valid values for index_structure are:

  • INGRES_STRUCTURE_CBTREE
  • INGRES_STRUCTURE_CISAM
  • INGRES_STRUCTURE_CHASH
  • INGRES_STRUCTURE_BTREE
  • INGRES_STRUCTURE_HASH
  • INGRES_STRUCTURE_ISAM
INGRES_STRUCTURE_HASH
login_local boolean Determines how the connection user ID and password are used when a VNODE is included in the target database string. If set to TRUE, the user ID and password are used to locally access the VNODE, and the VNODE login information is used to establish the DBMS connection. If set to FALSE, the process user ID is used to access the VNODE, and the connection user ID and password are used in place of the VNODE login information to establish the DBMS connection. This parameter is ignored if no VNODE is included in the target database string. The default is FALSE. TRUE
timezone string Controls the timezone of the session. If not set it will default to the value defined by II_TIMEZONE_NAME. If II_TIMEZONE_NAME is not defined, NA-PACIFIC (GMT-8 with Daylight Savings) is used.
date_format integer

Sets the allowable input and output format for Ingres dates. Defaults to the value defined by II_DATE_FORMAT. If II_DATE_FORMAT is not set the default date format is US, e.g. mm/dd/yy. Valid values for date_format are:

  • INGRES_DATE_DMY
  • INGRES_DATE_FINISH
  • INGRES_DATE_GERMAN
  • INGRES_DATE_ISO
  • INGRES_DATE_ISO4
  • INGRES_DATE_MDY
  • INGRES_DATE_MULTINATIONAL
  • INGRES_DATE_MULTINATIONAL4
  • INGRES_DATE_YMD
  • INGRES_DATE_US
INGRES_DATE_MULTINATIONAL4
decimal_separator string The character identifier for decimal data ","
money_lort integer

Leading or trailing currency sign. Valid values for money_lort are:

  • INGRES_MONEY_LEADING
  • INGRES_MONEY_TRAILING
INGRES_MONEY_TRAILING
money_sign string The currency symbol to be used with the MONEY datatype
money_precision integer The precision of the MONEY datatype 3
float4_precision integer Precision of the FLOAT4 datatype 10
float8_precision integer Precision of the FLOAT8 data 10
blob_segment_length integer The amount of data in bytes to fetch at a time when retrieving BLOB or CLOB data, defaults to 4096 bytes when not explicitly set 8192

返回值

Returns a Ingres link resource on success 或者在失败时返回 FALSE

范例

示例 #1 Open a connection to an Ingres database

<?php
$link = ingres_connect("mydb", "user", "pass")
    or die("Could not connect");
echo "Connected successfully";
ingres_close($link);
?>

参见

  • ingres_pconnect
  • ingres_close

ingres_cursor

Get a cursor name for a given result resource

说明

string ingres_cursor ( resource $result )

Returns a string with the active cursor name. If no cursor is active then NULL is returned.

参数

result
The query result identifier

返回值

Returns a string containing the active cursor name. If no cursor is active then NULL is returned.

范例

示例 #1 Get cursor name for a query resource

<?php
$link = ingres_connect($database, $user, $password);

$result = ingres_prepare($link, "select * from table");

$cursor_name = ingres_cursor($result);

echo $cursor_name;

?>

参见

  • ingres_prepare
  • ingres_execute

ingres_errno

Get the last Ingres error number generated

说明

int ingres_errno ([ resource $link ] )

Returns an integer containing the last error number. If no error was reported 0 is returned.

If a link resource is passed to ingres_errno it returns the last error recorded for the link. If no link is passed, then ingres_errno returns the last error reported using the default link.

The function, ingres_errno, should always be called after executing a database query. Calling another function before ingres_errno is called will reset or change any error code from the last Ingres function call.

参数

link
The connection link identifier

返回值

Returns an integer containing the last error number. If no error was reported, 0 is returned.

范例

示例 #1 Get the last Ingres error number generated

<?php
$link = ingres_connect($database, $user, $password);

$result = ingres_query($link, "select * from table");

$error_code = ingres_errno($link);

if ( $error_code != 0 ) {
   echo "An error occurred - " . $error_code;
}
?>

参见

  • ingres_error
  • ingres_errsqlstate
  • ingres_next_error

ingres_error

Get a meaningful error message for the last error generated

说明

string ingres_error ([ resource $link ] )

Returns a string containing the last error, or NULL if no error has occurred.

If a link resource is passed to ingres_error, it returns the last error recorded for the link. If no link is passed then ingres_error returns the last error reported using the default link.

The function, ingres_error, should always be called after executing any database query. Calling another function before ingres_error is called will reset or change any error message from the last Ingres function call.

参数

link
The connection link identifier

返回值

Returns a string containing the last error, or NULL if no error has occurred.

范例

示例 #1 Get a message for the last error generated

<?php
$link = ingres_connect($database, $user, $password);

$result = ingres_query($link, "select * from table");

$error_text = ingres_error();

if (!is_null($error_text)) {
   echo "An error occurred - " . $error_text;
}
?>

参见

  • ingres_errno
  • ingres_errsqlstate
  • ingres_next_error

ingres_errsqlstate

Get the last SQLSTATE error code generated

说明

string ingres_errsqlstate ([ resource $link ] )

Returns a string containing the last SQLSTATE, or NULL if no error has occurred.

If a link resource is passed to ingres_errsqlstate, it returns the last error recorded for the link. If no link is passed, then ingres_errsqlstate returns the last error reported using the default link.

The function, ingres_errsqlstate, should always be called after executing any database query. Calling another function before ingres_errsqlstate is called will reset or change any error message from the last Ingres function call.

参数

link
The connection link identifier

返回值

Returns a string containing the last SQLSTATE, or NULL if no error has occurred.

范例

示例 #1 Get the last SQLSTATE error code generated

<?php
$link = ingres_connect($database, $user, $password);

$result = ingres_query($link, "select * from table");

$error_sqlstate = ingres_errsqlstate($link);

if (!is_null($error_sqlstate)) {
   echo "An error occurred - " . $error_sqlstate;
}
?>

参见

  • ingres_errno
  • ingres_error
  • ingres_next_error

ingres_escape_string

Escape special characters for use in a query

说明

string ingres_escape_string ( resource $link , string $source_string )

ingres_escape_string is used to escape certain characters within a string before it is sent to the database server.

参数

link
The connection link identifier

source_string
The source string to be parsed

返回值

Returns a string containing the escaped data.

范例

示例 #1 Escape special characters for use in a query

<?php
$link = ingres_connect($database, $user, $password);

$last_name = "O'Connor";

$sql = sprintf("select * from user_profile where up_last = '%s'", ingres_escape_string( $link, $last_name));

$result = ingres_query($link, $sql);

while ($user = ingres_fetch_object($result))
{
  echo $user->up_first . '<BR/>';
}

ingres_commit($link);

ingres_close($link);

?>

参见

  • ingres_query

ingres_execute

Execute a prepared query

说明

bool ingres_execute ( resource $result [, array $params [, string $types ]] )

Execute a query prepared using ingres_prepare.

Note: Related Configurations

See also the ingres.describe, ingres.scrollable and ingres.utf8 directives in Runtime Configuration.

参数

result
The result query identifier

params
An array of parameter values to be used with the query

types
A string containing a sequence of types for the parameter values passed. See the types parameter in ingres_query for the list of type codes.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • ingres_unbuffered_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row
  • ingres_commit
  • ingres_rollback
  • ingres_autocommit
  • ingres_set_environment
  • ingres_errno
  • ingres_error

ingres_fetch_array

Fetch a row of result into an array

说明

array ingres_fetch_array ( resource $result [, int $result_type ] )

This function is an extended version of ingres_fetch_row. In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.

If two or more columns of the result have the same field names, the last column will take precedence. To access the another column or columns of the same name, you must use the numeric index of the column or make an alias for the column. For example:

<?php

$result = ingres_query($link, "select ap_place as city, ap_ccode as country from airport where ap_iatacode = 'VLL'"); 
$result = ingres_fetch_array($result);
$foo = $result["city"];
$bar = $result["country"];

?>

With regard to speed, the function is identical to ingres_fetch_object, and almost as quick as ingres_fetch_row (the difference is insignificant).

By default, arrays created by ingres_fetch_array start from position 1 and not 0 as with other DBMS extensions. The starting position can be adjusted to 0 using the configuration parameter ingres.array_index_start.

Note: Related Configurations

See also the ingres.array_index_start, ingres.fetch_buffer_size and ingres.utf8 directives in Runtime Configuration.

参数

result
The query result identifier

result_type
The result type. This result_type can be INGRES_NUM for enumerated array, INGRES_ASSOC for associative array, or INGRES_BOTH (default).

返回值

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows

范例

示例 #1 Fetch a row of result into an array

<?php
$link = ingres_connect($database, $user, $password);

$result = ingres_query($link,"select * from table");
while ($row = ingres_fetch_array($result)) {
    echo $row["user_id"];  // using associative array
    echo $row["fullname"];
    echo $row[1];          // using enumerated array
    echo $row[2];
}
?>

参见

  • ingres_query
  • ingres_num_fields
  • ingres_field_name
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_fetch_assoc

Fetch a row of result into an associative array

说明

array ingres_fetch_assoc ( resource $result )

This function is stores the data fetched from a query executed using ingres_query in an associative array, using the field names as keys.

With regard to speed, the function is identical to ingres_fetch_object, and almost as quick as ingres_fetch_row (the difference is insignificant).

By default, arrays created by ingres_fetch_assoc start from position 1 and not 0 as with other DBMS extensions. The starting position can be adjusted to 0 using the configuration parameter ingres.array_index_start.

Note: Related Configurations

See also the ingres.array_index_start, ingres.fetch_buffer_size and ingres.utf8 directives in Runtime Configuration.

参数

result
The query result identifier

返回值

Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows

范例

示例 #1 Fetch a row into an associative array

<?php
$link = ingres_connect($database, $user, $password);

$result = ingres_query($link,"select * from table");
while ($row = ingres_fetch_assoc($result)) {
    echo $row["user_id"];  // using associative array
    echo $row["fullname"];
}
?>

参见

  • ingres_query
  • ingres_num_fields
  • ingres_field_name
  • ingres_fetch_array
  • ingres_fetch_object
  • ingres_fetch_row

ingres_fetch_object

Fetch a row of result into an object

说明

object ingres_fetch_object ( resource $result [, int $result_type ] )

This function is similar to ingres_fetch_array, with one difference - an object is returned instead of an array. Indirectly, this means that you can access the data only by the field names and not by their offsets (numbers are illegal property names).

With regard to speed, the function is identical to ingres_fetch_array, and almost as quick as ingres_fetch_row (the difference is insignificant).

Note: Related Configurations

See also the ingres.fetch_buffer_size and ingres.utf8 directives in Runtime Configuration.

参数

link
The query result identifier

result_type
(Optional argument.) result_type is a constant and can take the following values: INGRES_ASSOC, INGRES_NUM, and INGRES_BOTH.

返回值

Returns an object that corresponds to the fetched row, or FALSE if there are no more rows

范例

示例 #1 Fetch a row into an object

<?php
$link = ingres_connect($database, $user, $password);
$result = ingres_query($link, "select * from table");
while ($row = ingres_fetch_object($result)) {
    echo $row->user_id;
    echo $row->fullname;
}
?>

参见

  • ingres_query
  • ingres_num_fields
  • ingres_field_name
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_row

ingres_fetch_proc_return

Get the return value from a procedure call

说明

int ingres_fetch_proc_return ( resource $result )

This function is used to retrieve the return value following the execution of an Ingres database procedure (stored procedure).

Note:

If used with a row-producing procedure, this function should be called after all the rows from the procedure have been fetched using class="function">ingres_fetch_array, class="function">ingres_fetch_object or class="function">ingres_fetch_row. This function will eliminate any rows yet to be fetched should there be any left over.

参数

result
The result identifier for a query

返回值

Returns an integer if there is a return value otherwise it will return NULL.

范例

示例 #1 Get the return value from a procedure call

<?php

$link = ingres_connect($database);

if ( ingres_errno() != 0 ) {
    $error_text = ingres_error();
    die($error_text);
}

$result = ingres_query($link, "execute procedure php_proc (value = 1000)");

if ( ingres_errno() != 0 ) {
    $error_text = ingres_error();
    die($error_text);
}

echo "return value - " . ingres_fetch_proc_return($result) . "\n";

ingres_close($link);

?>

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_object
  • ingres_fetch_row

ingres_fetch_row

Fetch a row of result into an enumerated array

说明

array ingres_fetch_row ( resource $result )

ingres_fetch_row returns an array that corresponds to the fetched row, or FALSE if there are no more rows. Each result column is stored in an array offset, starting at offset 1.

Subsequent calls to ingres_fetch_row return the next row in the result set, or FALSE if there are no more rows.

By default, arrays created by ingres_fetch_row start from position 1 and not 0 as with other DBMS extensions. The starting position can be adjusted to 0 using the configuration parameter ingres.array_index_start.

Note: Related Configurations

See also the ingres.array_index_start, ingres.fetch_buffer_size and ingres.utf8 directives in Runtime Configuration.

参数

result
The query result identifier

返回值

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows

范例

示例 #1 Fetch a row of result into an enumerated array

<?php
$link = ingres_connect($database, $user, $password);

$result = ingres_query($link, "select * from table");
while ($row = ingres_fetch_row($result)) {
    echo $row[1];
    echo $row[2];
}
?>

参见

  • ingres_num_fields
  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object

ingres_field_length

Get the length of a field

说明

int ingres_field_length ( resource $result , int $index )

ingres_field_length returns the length of a field. This is the number of bytes the server uses to store the field. For detailed information, see the Ingres OpenAPI User Guide, Appendix "Data Types" in the Ingres documentation.

Note: Related Configurations

See ingres.array_index_start in Runtime Configuration

参数

result
The query result identifier

index
index is the column number whose length will be retrieved.

The possible values of index depend upon the value of ingres.array_index_start. If ingres.array_index_start is 1 (the default) then index must be between 1 and the value returned by ingres_num_fields. If ingres.array_index_start is 0 then index must be between 0 and ingres_num_fields - 1.

返回值

Returns the length of a field.

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_field_name

Get the name of a field in a query result

说明

string ingres_field_name ( resource $result , int $index )

ingres_field_name returns the name of a field in a query result.

Note: Related Configurations

See ingres.array_index_start in Runtime Configuration

参数

result
The query result identifier

index
index is the field whose name will be retrieved.

The possible values of index depend upon the value of ingres.array_index_start. If ingres.array_index_start is 1 (the default) then index must be between 1 and the value returned by ingres_num_fields. If ingres.array_index_start is 0 then index must be between 0 and ingres_num_fields - 1.

返回值

Returns the name of a field in a query result 或者在失败时返回 FALSE

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_field_nullable

Test if a field is nullable

说明

bool ingres_field_nullable ( resource $result , int $index )

Test if a field is nullable.

Note: Related Configurations

See ingres.array_index_start in Runtime Configuration

参数

result
The query result identifier

index
index is the field whose nullability will be retrieved.

The possible values of index depend upon the value of ingres.array_index_start. If ingres.array_index_start is 1 (the default) then index must be between 1 and the value returned by ingres_num_fields. If ingres.array_index_start is 0 then index must be between 0 and ingres_num_fields - 1.

返回值

ingres_field_nullable returns TRUE if the field can be set to the NULL value and FALSE if it cannot

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_field_precision

Get the precision of a field

说明

int ingres_field_precision ( resource $result , int $index )

ingres_field_precision returns the precision of a field. This value is used only for decimal, float, and money SQL data types. For detailed information, see the Ingres OpenAPI User Guide, Appendix "Data Types" in the Ingres documentation.

Note: Related Configurations

See ingres.array_index_start in Runtime Configuration

参数

result
The query result identifier

index
index is the field whose precision will be retrieved.

The possible values of index depend upon the value of ingres.array_index_start. If ingres.array_index_start is 1 (the default) then index must be between 1 and the value returned by ingres_num_fields. If ingres.array_index_start is 0 then index must be between 0 and ingres_num_fields - 1.

返回值

Returns the field precision as an integer

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_field_scale

Get the scale of a field

说明

int ingres_field_scale ( resource $result , int $index )

ingres_field_scale returns the scale of a field. This value is used only for the decimal SQL data type. For detailed information, see the Ingres OpenAPI User Guide, Appendix "Data Types" in the Ingres documentation.

Note: Related Configurations

See ingres.array_index_start in Runtime Configuration

参数

result
The query result identifier

index
index is the field whose scale will be retrieved.

The possible values of index depend upon the value of ingres.array_index_start. If ingres.array_index_start is 1 (the default) then index must be between 1 and the value returned by ingres_num_fields. If ingres.array_index_start is 0 then index must be between 0 and ingres_num_fields - 1.

返回值

Returns the scale of the field, as an integer

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_field_type

Get the type of a field in a query result

说明

string ingres_field_type ( resource $result , int $index )

Get the type of a field in a query result.

Note: Related Configurations

See ingres.array_index_start in Runtime Configuration

参数

result
The query result identifier

index
index is the field whose type will be retrieved.

The possible values of index depend upon the value of ingres.array_index_start. If ingres.array_index_start is 1 (the default) then index must be between 1 and the value returned by ingres_num_fields. If ingres.array_index_start is 0 then index must be between 0 and ingres_num_fields - 1.

返回值

ingres_field_type returns the type of a field in a query result 或者在失败时返回 FALSE. Examples of types returned are IIAPI_BYTE_TYPE, IIAPI_CHA_TYPE, IIAPI_DTE_TYPE, IIAPI_FLT_TYPE, IIAPI_INT_TYPE, IIAPI_VCH_TYPE. Some of these types can map to more than one SQL type depending on the length of the field (see ingres_field_length). For example IIAPI_FLT_TYPE can be a float4 or a float8. For detailed information, see the Ingres OpenAPI User Guide, Appendix "Data Types" in the Ingres documentation.

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_free_result

Free the resources associated with a result identifier

说明

bool ingres_free_result ( resource $result )

参数

result
The query result identifier

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 Free a result resource

<?php
$link = ingres_connect($database, $user, $password);

$result = ingres_query($link, "select * from table");

while ($row = ingres_fetch_row($result)) {
    echo $row[1];
    echo $row[2];
}
ingres_free_result($result);

ingres_close($link)

?>

参见

  • ingres_query

ingres_next_error

Get the next Ingres error

说明

bool ingres_next_error ([ resource $link ] )

Get the next Ingres error for the last executed query. Each call to ingres_next_error can be followed by a call to ingres_errno, ingres_error or ingres_errsqlstate to get the respective error number, error text, or SQL STATE. While ingres_next_error returns TRUE, there are more errors to fetch.

参数

link
The connection link identifier

返回值

ingres_next_error returns TRUE if there is another error to retrieve or FALSE when there are no more errors

参见

  • ingres_errno
  • ingres_error
  • ingres_errsqlstate

ingres_num_fields

Get the number of fields returned by the last query

说明

int ingres_num_fields ( resource $result )

ingres_num_fields returns the number of fields in the results returned by the Ingres server after a call to ingres_query.

参数

result
The query result identifier

返回值

Returns the number of fields

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_num_rows

Get the number of rows affected or returned by a query

说明

int ingres_num_rows ( resource $result )

This function primarily is meant to get the number of rows modified in the database. However, it can be used to retrieve the number of rows to fetch for a SELECT statement.

Note:

If scrollable cursors are disabled and this function is called before using class="function">ingres_fetch_array, class="function">ingres_fetch_object, or class="function">ingres_fetch_row, the server will delete the result's data and the script will be unable to get them.

Instead, you should retrieve the result's data using one of these fetch functions in a loop until it returns FALSE, indicating that no more results are available.

参数

result
The result identifier for a query

返回值

For delete, insert, or update queries, ingres_num_rows returns the number of rows affected by the query. For other queries, ingres_num_rows returns the number of rows in the query's result.

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_pconnect

Open a persistent connection to an Ingres database

说明

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

Open a persistent connection to an Ingres database.

There are only two differences between this function and ingres_connect: First, when connecting, the function will initially try to find a (persistent) link that is already opened with the same parameters. If one is found, an identifier for it will be returned instead of opening a new connection. Second, the connection to the Ingres server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (ingres_close will not close links established by ingres_pconnect). This type of link is therefore called "persistent".

参数

database
The database name. Must follow the syntax:

[vnode::]dbname[/svr_class]

username
The Ingres user name

password
The password associated with username

options
See ingres_connect for the list of options that can be passed

返回值

Returns an Ingres link resource on success 或者在失败时返回 FALSE

参见

  • ingres_connect
  • ingres_close

ingres_prepare

Prepare a query for later execution

说明

mixed ingres_prepare ( resource $link , string $query )

Prepares a query for execution by ingres_execute.

The query becomes part of the currently open transaction. If there is no open transaction, ingres_query opens a new transaction. To close the transaction, you can call either ingres_commit to commit the changes made to the database or ingres_rollback to cancel these changes. When the script ends, any open transaction is rolled back (by calling ingres_rollback). You can also use ingres_autocommit before opening a new transaction to have every SQL query immediately committed.

Note: Related Configurations

See also the ingres.describe, ingres.scrollable and ingres.utf8 directives in Runtime Configuration.

参数

link
The connection link identifier

query
A valid SQL query (see the Ingres SQL reference guide) in the Ingres documentation. See the query parameter in ingres_query for a list of SQL statements which cannot be executed using ingres_prepare

返回值

ingres_prepare returns a query result identifier that is used with ingres_execute to execute the query. To see if an error occurred, use ingres_errno, ingres_error, or ingres_errsqlstate.

参见

  • ingres_unbuffered_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row
  • ingres_commit
  • ingres_rollback
  • ingres_autocommit
  • ingres_set_environment
  • ingres_errno
  • ingres_error

ingres_query

Send an SQL query to Ingres

说明

mixed ingres_query ( resource $link , string $query [, array $params [, string $types ]] )

ingres_query sends the given query to the Ingres server.

The query becomes part of the currently open transaction. If there is no open transaction, ingres_query opens a new transaction. To close the transaction, you can call either ingres_commit to commit the changes made to the database or ingres_rollback to cancel these changes. When the script ends, any open transaction is rolled back (by calling ingres_rollback). You can also use ingres_autocommit before opening a new transaction to have every SQL query immediately committed.

Note: Related Configurations

See also the ingres.describe, ingres.scrollable and ingres.utf8 directives in Runtime Configuration

参数

link
The connection link identifier.

query
A valid SQL query (see the Ingres SQL reference guide) in the Ingres documentation.

Data inside the query should be properly escaped.

The following types of SQL queries cannot be sent with this function:

  • close (see ingres_close)
  • commit (see ingres_commit)
  • connect (see ingres_connect)
  • disconnect (see ingres_close)
  • get dbevent
  • prepare to commit
  • rollback (see ingres_rollback)
  • savepoint
  • set autocommit (see ingres_autocommit)
  • all cursor-related queries are unsupported

params
An array of parameter values to be used with the query

types
A string containing a sequence of types for the parameter values passed. When ingres.describe is enabled, this parameter can be ignored as the driver automatically fetches the expected parameter types from the server.

Type codeIngres type
aBOOLEAN
bBYTE
BLONG BYTE/BLOB
cCHAR
dDATE/ANSIDATE/TIMESTAMP/TIME
fFLOAT
iINTEGER
LLONG TEXT
mMONEY
MLONG NVARCHAR
nNCHAR
NNVARCHAR
tTEXT
vVARCHAR
VLONG VARCHAR

返回值

ingres_query returns a query result identifier on success else it returns FALSE. To see if an error occurred use ingres_errno, ingres_error or ingres_errsqlstate.

范例

示例 #1 Send a simple select

<?php
$link = ingres_connect("demodb");

$result = ingres_query($link, "select * from user_profile");
while ($row = ingres_fetch_row($result)) {
    echo $row[1];
    echo $row[2];
}
?>

示例 #2 Passing query parameters to ingres_query

<?php
$link = ingres_connect("demodb");

$params[] = "Emma";
$query = "select * from user_profile where up_first = ?";
$result = ingres_query($link, $query, $params);
while ($row = ingres_fetch_row($result)) {
    echo $row[1];
    echo $row[2];
}
?>

示例 #3 Inserting a BLOB with parameter types

<?php
$link = ingres_connect("demodb");

//Open a photo
$fh = fopen("photo.jpg","r");
$blob_data = stream_get_contents($fh);
fclose($fh);

//Prepare parameters
$params[] = $blob_data;
$params[] = 1201;

//Define parameter types
$param_types = "Bi";

$query = "update user_profile set up_image = ? where up_id = ?";
$result = ingres_query($link, $query , $params, $param_types);

if (ingres_errno())
{
    echo ingres_errno() . "-" . ingres_error() . "\n";
}

ingres_commit($link);

ingres_close($link);
?>

参见

  • ingres_unbuffered_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row
  • ingres_commit
  • ingres_rollback
  • ingres_autocommit
  • ingres_set_environment
  • ingres_errno
  • ingres_error

ingres_result_seek

Set the row position before fetching data

说明

bool ingres_result_seek ( resource $result , int $position )

This function is used to position the cursor associated with the result resource before issuing a fetch. If ingres.array_index_start is set to 0 then the first row is 0 else it is 1. ingres_result_seek can be used only with queries that make use of scrollable cursors. It cannot be used with ingres_unbuffered_query.

Note: Related Configurations

See also the ingres.scrollable and ingres.array_index_start directives in Runtime Configuration.

参数

result
The result identifier for a query

position
The row to position the cursor on. If ingres.array_index_start is set to 0, then the first row is 0, else it is 1

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 Position the cursor on the 3rd row

<?php

$result=ingres_query($link, "select * from airport where ap_ccode = 'ES' order by ap_place asc");

/* goto row 3 */
if (!ingres_result_seek($result, 3))
{
    echo ingres_errno() . " - " . ingres_error . "\n";
    die("i died");
}
else
{
    $airport = ingres_fetch_object ($result);
    {
        echo $airport->ap_iatacode . " - " .  $airport->ap_name . "\n";
    }
}

ingres_commit($link);

?>

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row

ingres_rollback

Roll back a transaction

说明

bool ingres_rollback ( resource $link )

ingres_rollback rolls back the currently open transaction, actually cancelling all changes made to the database during the transaction.

This closes the transaction. A new transaction can be opened by sending a query with ingres_query.

参数

link
The connection link identifier

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • ingres_query
  • ingres_commit
  • ingres_autocommit

ingres_set_environment

Set environment features controlling output options

说明

bool ingres_set_environment ( resource $link , array $options )

ingres_set_environment is called to set environmental options that affect the output of certain values from Ingres, such as the timezone, date format, decimal character separator, and float precision.

参数

link
The connection link identifier

options
An enumerated array of option name/value pairs. The following table lists the option name and the expected type

Option name Option type Description Example
date_century_boundary integer The threshold by which a 2-digit year is determined to be in the current century or in the next century. Equivalent to II_DATE_CENTURY_BOUNDARY 50
timezone string Controls the timezone of the session. If not set, it will default the value defined by II_TIMEZONE_NAME. If II_TIMEZONE_NAME is not defined, NA-PACIFIC (GMT-8 with Daylight Savings) is used. UNITED-KINGDOM
date_format integer

Sets the allowable input and output format for Ingres dates. Defaults to the value defined by II_DATE_FORMAT. If II_DATE_FORMAT is not set, the default date format is US, for example mm/dd/yy. Valid values for date_format are:

  • INGRES_DATE_DMY
  • INGRES_DATE_FINISH
  • INGRES_DATE_GERMAN
  • INGRES_DATE_ISO
  • INGRES_DATE_ISO4
  • INGRES_DATE_MDY
  • INGRES_DATE_MULTINATIONAL
  • INGRES_DATE_MULTINATIONAL4
  • INGRES_DATE_YMD
  • INGRES_DATE_US
INGRES_DATE_ISO4
decimal_separator string The character identifier for decimal data ","
money_lort integer

Leading or trailing currency sign. Valid values for money_lort are:

  • INGRES_MONEY_LEADING
  • INGRES_MONEY_TRAILING
INGRES_MONEY_LEADING
money_sign string The currency symbol to be used with the MONEY datatype
money_precision integer The precision of the MONEY datatype 2
float4_precision integer Precision of the FLOAT4 datatype 10
float8_precision integer Precision of the FLOAT8 data 10
blob_segment_length integer The amount of data in bytes to fetch at a time when retrieving BLOB or CLOB data. Defaults to 4096 bytes when not set explicitly 8192

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 Set date_format to ISO4

<?php
$options = array( "date_format" => INGRES_DATE_ISO4 );

if (ingres_set_environment($link, $options))
{
    $result=ingres_query($link,"select date('now') as date");

    while ( $object = ingres_fetch_object ($result) ) {
        echo $object->date."\n";
    }
}
?>

示例 #2 Set timezone to HONG-KONG

<?php

$options = array( "timezone" => "HONG-KONG");

if (ingres_set_environment($link, $options))
{
    $result=ingres_query($link,"select date('now') as date");

    while ( $object = ingres_fetch_object ($result) ) {
        echo $object->date."\n";
    }
}
?>

参见

  • ingres_connect
  • ingres_query

ingres_unbuffered_query

Send an unbuffered SQL query to Ingres

说明

mixed ingres_unbuffered_query ( resource $link , string $query [, array $params [, string $types ]] )

ingres_unbuffered_query sends the given query to the Ingres server.

The query becomes part of the currently open transaction. If there is no open transaction, ingres_unbuffered_query opens a new transaction. To close the transaction, you can call either ingres_commit to commit the changes made to the database or ingres_rollback to cancel these changes. When the script ends, any open transaction is rolled back (by calling ingres_rollback). You can also use ingres_autocommit before opening a new transaction to have every SQL query immediately committed. Ingres allows only a single unbuffered statement to be active at any one time. The extension will close any active unbuffered statements before executing any SQL. In addition you cannot use ingres_result_seek to position the row before fetching.

Note: Related Configurations

See also the ingres.describe and ingres.utf8 directives in Runtime Configuration.

参数

link
The connection link identifier

query
A valid SQL query (see the Ingres SQL reference guide) in the Ingres documentation. See the query parameter in ingres_query for a list of SQL statements that cannot be executed via ingres_unbuffered_query.

Data inside the query should be properly escaped.

params
An array of parameter values to be used with the query

types
A string containing a sequence of types for the parameter values passed. See the types parameter in ingres_query for the list of type codes.

返回值

ingres_unbuffered_query returns a query result identifier when there are rows to fetch; else it returns FALSE when there are no rows, as is the case of an INSERT, UPDATE, or DELETE statement. To see if an error occurred, use ingres_errno, ingres_error, or ingres_errsqlstate.

范例

示例 #1 Issue a simple un-buffered select

<?php
$link = ingres_connect("demodb");

$result = ingres_unbuffered_query($link, "select * from user_profile");
while ($row = ingres_fetch_row($result)) {
    echo $row[1];
    echo $row[2];
}
?>

示例 #2 Passing query parameters to ingres_unbuffered_query

<?php
$link = ingres_connect("demodb");

$params[] = "Emma";
$query = "select * from user_profile where up_first = ?";
$result = ingres_unbuffered_query($link, $query, $params);
while ($row = ingres_fetch_row($result)) {
    echo $row[1];
    echo $row[2];
}
?>

示例 #3 Inserting a BLOB with parameter types

<?php
$link = ingres_connect("demodb");

//Open a photo
$fh = fopen("photo.jpg","r");
$blob_data = stream_get_contents($fh);
fclose($fh);

//Prepare parameters
$params[] = $blob_data;
$params[] = 1201;

//Define parameter types
$param_types = "Bi";

$query = "update user_profile set up_image = ? where up_id = ?";
$result = ingres_unbuffered_query($link, $query , $params, $param_types);

if (ingres_errno())
{
    echo ingres_errno() . "-" . ingres_error() . "\n";
}
?>

参见

  • ingres_query
  • ingres_fetch_array
  • ingres_fetch_assoc
  • ingres_fetch_object
  • ingres_fetch_row
  • ingres_commit
  • ingres_rollback
  • ingres_autocommit
  • ingres_set_environment
  • ingres_errno
  • ingres_error

目录