Book/ingres-Phpdoc专题

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, <span class="function">ingres_connect becomes <span class="function">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_SYSTEM Available since ingres 1.0.0
ingres.array_index_start "1" PHP_INI_ALL Available since ingres 1.4.0.
ingres.auto "1" PHP_INI_ALL Available since ingres 2.0.0.
ingres.blob_segment_length "4096" PHP_INI_ALL Available since ingres 1.2.0.
ingres.cursor_mode "0" PHP_INI_ALL Available since ingres 1.1.0.
ingres.default_database NULL PHP_INI_ALL Available since ingres 1.0.0
ingres.default_password NULL PHP_INI_ALL Available since ingres 1.0.0
ingres.default_user NULL PHP_INI_ALL Available since ingres 1.0.0
ingres.describe 1 PHP_INI_ALL Available since ingres 2.1.0
ingres.fetch_buffer_size 100 PHP_INI_ALL Available since ingres 2.1.0
ingres.max_links "-1" PHP_INI_SYSTEM Available since ingres 1.0.0
ingres.max_persistent "-1" PHP_INI_SYSTEM Available since ingres 1.0.0
ingres.reuse_connection "1" PHP_INI_ALL Available since ingres 2.0.0
ingres.scrollable "1" PHP_INI_ALL Available since ingres 2.0.0.
ingres.trace "0" PHP_INI_ALL Available since ingres 2.0.0.
ingres.trace_connect "0" PHP_INI_ALL Available since ingres 1.2.1.
ingres.utf8 "1" PHP_INI_ALL Available since ingres 2.0.0.

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

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

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

ingres.array_index_start int
Specifies the start value for an integer key for arrays generated by ingres_fetch_row or <span class="function">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 bool
Enables or disables autocommit emulation. Ingres cannot have multiple cursors open with autocommit enabled. When enabled, the driver emulates autocommit.

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

ingres.cursor_mode int
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 bool
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 <span class="function">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 <span class="function">ingres_prepare and <span class="function">ingres_execute.

ingres.fetch_buffer_size int
Specifies the number of pre-fetch rows that <span class="function">ingres_fetch_array, <span class="function">ingres_fetch_object and <span class="function">ingres_fetch_row will try and fetch in one fetch operation.

ingres.max_links int
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 int
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 bool
Reuses an existing active connection if connecting to the same database with the same user name

ingres.scrollable bool
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 bool
Enables simple tracing using E_NOTICE messages

ingres.trace_connect bool
Prints E_NOTICE messages during <span class="function">ingres_connect or <span class="function">ingres_pconnect calls

ingres.utf8 bool
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 <span class="function">ingres_pconnect return an Ingres link identifier.

ingres_query and <span class="function">ingres_unbuffered_query return an Ingres result identifier.

预定义常量

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

INGRES_ASSOC (int)
Columns are returned into the array having the fieldname as the array index. Used with <span class="function">ingres_fetch_array.

INGRES_NUM (int)
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 (int)
Columns are returned into the array having both a numerical index and the fieldname as the array index. Used with <span class="function">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 (int)
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 (int)
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 (int)
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 (int)
Equivalent to the II_DATE_FORMAT setting of MULTINATIONAL. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_DATE_MULTINATIONAL4 (int)
Equivalent to the II_DATE_FORMAT setting of MULTINATIONAL4. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_DATE_FINNISH (int)
Equivalent to the II_DATE_FORMAT setting of FINNISH. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_DATE_ISO (int)
Equivalent to the II_DATE_FORMAT setting of ISO. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_DATE_ISO4 (int)
Equivalent to the II_DATE_FORMAT setting of ISO4. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_DATE_GERMAN (int)
Equivalent to the II_DATE_FORMAT setting of GERMAN. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_DATE_MDY (int)
Equivalent to the II_DATE_FORMAT setting of MDY. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_DATE_DMY (int)
Equivalent to the II_DATE_FORMAT setting of DMY. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_DATE_YMD (int)
Equivalent to the II_DATE_FORMAT setting of YMD. Available since version 1.2.0 of the PECL extension. Used with ingres_connect, <span class="function">ingres_pconnect and <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_MONEY_LEADING (int)
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 <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_MONEY_TRAILING (int)
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 <span class="function">ingres_set_environment. See options in <span class="function">ingres_set_environment.

INGRES_STRUCTURE_BTREE (int)
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 <span class="function">ingres_connect.

INGRES_STRUCTURE_CBTREE (int)
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 <span class="function">ingres_connect and <span class="function">ingres_pconnect. See options in <span class="function">ingres_connect.

INGRES_STRUCTURE_HASH (int)
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 <span class="function">ingres_connect.

INGRES_STRUCTURE_CHASH (int)
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 <span class="function">ingres_connect and <span class="function">ingres_pconnect. See options in <span class="function">ingres_connect.

INGRES_STRUCTURE_HEAP (int)
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 <span class="function">ingres_connect and <span class="function">ingres_pconnect. See options in <span class="function">ingres_connect.

INGRES_STRUCTURE_CHEAP (int)
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 <span class="function">ingres_pconnect. See options in <span class="function">ingres_connect.

INGRES_STRUCTURE_ISAM (int)
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 <span class="function">ingres_connect.

INGRES_STRUCTURE_CISAM (int)
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 <span class="function">ingres_connect and <span class="function">ingres_pconnect. See options in <span class="function">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 <span class="methodname">ingres_autocommit_state ( <span class="methodparam">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 <span class="methodname">ingres_autocommit ( <span class="methodparam">resource $link )

ingres_autocommit is called before opening a transaction (before the first call to <span class="function">ingres_query or just after a call to <span class="function">ingres_rollback or <span class="function">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, <span class="function">ingres_autocommit_state.

By default Ingres will rollback any uncommitted transactions at the end of a request. Use this function or <span class="function">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 <span class="methodname">ingres_charset ( <span class="methodparam">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 <span 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 <span class="methodname">ingres_close ( <span class="methodparam">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 <span class="methodname">ingres_commit ( <span class="methodparam">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 <span class="function">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<span class="type">false <span class="methodname">ingres_connect ([ <span class="methodparam">string $database [, string $username [, <span class="type">string $password [, <span class="methodparam">array $options ]]]] )

ingres_connect opens a connection with the given Ingres database.

The connection is closed when the script ends or when <span class="function">ingres_close is called on this link.

参数

If some parameters are missing, <span class="function">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 int 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 bool 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 int

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 int

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 int The precision of the MONEY datatype 3
float4_precision int Precision of the FLOAT4 datatype 10
float8_precision int Precision of the FLOAT8 data 10
blob_segment_length int 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 <span class="methodname">ingres_cursor ( <span class="methodparam">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 <span class="methodname">ingres_errno ([ <span class="methodparam">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 <span class="function">ingres_errno it returns the last error recorded for the link. If no link is passed, then <span class="function">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 <span class="methodname">ingres_error ([ <span class="methodparam">resource $link ] )

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

If a link resource is passed to <span class="function">ingres_error, it returns the last error recorded for the link. If no link is passed then <span class="function">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 <span class="methodname">ingres_errsqlstate ([ <span class="methodparam">resource $link ] )

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

If a link resource is passed to <span class="function">ingres_errsqlstate, it returns the last error recorded for the link. If no link is passed, then <span class="function">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 <span class="methodname">ingres_escape_string ( <span class="methodparam">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 <span class="methodname">ingres_execute ( <span class="methodparam">resource $result [, array $params [, <span class="type">string $types ]] )

Execute a query prepared using <span class="function">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 <span class="methodname">ingres_fetch_array ( <span class="methodparam">resource $result [, int $result_type ] )

This function is an extended version of <span class="function">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 <span class="function">ingres_fetch_object, and almost as quick as ingres_fetch_row (the difference is insignificant).

By default, arrays created by <span class="function">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 <span class="methodname">ingres_fetch_assoc ( <span class="methodparam">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 <span class="function">ingres_fetch_object, and almost as quick as ingres_fetch_row (the difference is insignificant).

By default, arrays created by <span class="function">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 <span class="methodname">ingres_fetch_object ( <span class="methodparam">resource $result [, int $result_type ] )

This function is similar to <span class="function">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 <span class="function">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 <span class="methodname">ingres_fetch_proc_return ( <span class="methodparam">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 <span class="function">ingres_fetch_array, <span class="function">ingres_fetch_object or <span 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 int 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 <span class="methodname">ingres_fetch_row ( <span class="methodparam">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 <span class="function">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 <span class="methodname">ingres_field_length ( <span class="methodparam">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 <span class="function">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<span class="type">false <span class="methodname">ingres_field_name ( <span class="methodparam">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 <span class="function">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 <span class="methodname">ingres_field_nullable ( <span class="methodparam">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 <span class="function">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 <span class="methodname">ingres_field_precision ( <span class="methodparam">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 <span class="function">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 <span class="methodname">ingres_field_scale ( <span class="methodparam">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 <span class="function">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<span class="type">false <span class="methodname">ingres_field_type ( <span class="methodparam">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 <span class="function">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 <span class="function">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 <span class="methodname">ingres_free_result ( <span class="methodparam">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 <span class="methodname">ingres_next_error ([ <span class="methodparam">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, <span class="function">ingres_error or <span class="function">ingres_errsqlstate to get the respective error number, error text, or SQL STATE. While <span class="function">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 <span class="methodname">ingres_num_fields ( <span class="methodparam">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 <span class="methodname">ingres_num_rows ( <span class="methodparam">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 <span class="function">ingres_fetch_array, <span class="function">ingres_fetch_object, or <span 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, <span class="function">ingres_num_rows returns the number of rows affected by the query. For other queries, <span class="function">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<span class="type">false <span class="methodname">ingres_pconnect ([ <span class="methodparam">string $database [, string $username [, <span class="type">string $password [, <span class="methodparam">array $options ]]]] )

Open a persistent connection to an Ingres database.

There are only two differences between this function and <span class="function">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 <span class="methodname">ingres_prepare ( <span class="methodparam">resource $link , string $query )

Prepares a query for execution by <span class="function">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 <span class="function">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 <span class="function">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 <span class="function">ingres_execute to execute the query. To see if an error occurred, use ingres_errno, ingres_error, or <span class="function">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 <span class="methodname">ingres_query ( <span class="methodparam">resource $link , string $query [, <span class="type">array $params [, <span class="methodparam">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 <span class="function">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 <span class="function">ingres_close)
  • commit (see <span class="function">ingres_commit)
  • connect (see <span class="function">ingres_connect)
  • disconnect (see <span class="function">ingres_close)
  • get dbevent
  • prepare to commit
  • rollback (see <span class="function">ingres_rollback)
  • savepoint
  • set autocommit (see <span class="function">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 code Ingres type
a BOOLEAN
b BYTE
B LONG BYTE/BLOB
c CHAR
d DATE/ANSIDATE/TIMESTAMP/TIME
f FLOAT
i INTEGER
L LONG TEXT
m MONEY
M LONG NVARCHAR
n NCHAR
N NVARCHAR
t TEXT
v VARCHAR
V LONG VARCHAR

返回值

ingres_query returns a query result identifier on success else it returns false. To see if an error occurred use ingres_errno, <span class="function">ingres_error or <span class="function">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 <span class="function">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 <span class="methodname">ingres_result_seek ( <span class="methodparam">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. <span class="function">ingres_result_seek can be used only with queries that make use of scrollable cursors. It cannot be used with <span class="function">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 <span class="methodname">ingres_rollback ( <span class="methodparam">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 <span class="methodname">ingres_set_environment ( <span class="methodparam">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 int 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 int

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 int

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 int The precision of the MONEY datatype 2
float4_precision int Precision of the FLOAT4 datatype 10
float8_precision int Precision of the FLOAT8 data 10
blob_segment_length int 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 <span class="methodname">ingres_unbuffered_query ( <span class="methodparam">resource $link , string $query [, <span class="type">array $params [, <span class="methodparam">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, <span class="function">ingres_unbuffered_query opens a new transaction. To close the transaction, you can call either <span class="function">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 <span class="function">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 <span class="function">ingres_query for a list of SQL statements that cannot be executed via <span class="function">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 <span class="function">ingres_errno, <span class="function">ingres_error, or <span class="function">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 <span class="function">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

目录


本站为非盈利网站,作品由网友提供上传,如无意中有侵犯您的版权,请联系删除