Informix PHP

Informix makes several specialized relational database servers for Windows NT and UNIX. Like Oracle and Sybase, Informix products are intended for demanding situations.

PHP includes support for two parts of the Informix API, ODS and IUS. The functions that begin with ifx_, such as ifx_pconnect, are part of ODS and should be available to you. The IUS functions begin with ifxus_, such as ifxus_create_slob. These will be available only if you have IUS libraries. Keep in mind that ODBC drivers for Informix are available, so you could pursue using PHP's ODBC functions instead. Jouni Ahto, Christian Cartus, and Danny Heijl collaborated to create the Informix extension.

integer ifx_affected_rows(integer result)
The ifx_affected_rows function returns the number of rows selected, inserted, updated, or deleted, depending on the query. If the query was a select, the number is only an estimate. You can use this function on a result identifier returned by ifx_prepare in order to avoid executing queries that will return large result sets.

boolean ifx_blobinfile_mode(integer mode)
Use ifx_blobinfile function to control how to work with blobs. If mode is 0, blobs are saved in memory. If mode is 1, blobs are saved to disk.

boolean ifx_byteasvarchar(integer mode)
Use ifx_byteasvarchar to control how byte blobs are returned in queries. If mode is 0, blob IDs are returned. If mode is 1, blob contents are returned.

boolean ifx_close(integer link)
The ifx_close function closes a database connection created by ifx_connect. If the optional link argument is left out, the last-opened connection is closed.

integer ifx_connect(string database, string user, string password)
The ifx_connect function returns a connection to an Informix database. All of the arguments are optional and will draw their values from the php.ini file if necessary. If a connection cannot be established, FALSE is returned. If you attempt to connect again after successfully connecting, the original connection identifier is returned. The connection will be closed automatically when the script ends, but you can close it manually with ifx_close. The ifx_pconnect function creates a persistent connection.

integer ifx_copy_blob(integer blob)
The ifx_copy_blob function makes a copy of an existing blob and returns the identifier to the new blob.

integer ifx_create_blob(integer type, integer mode, string data)
The ifx_create_blob function creates a blob in the database. The type argument can be 1 for text or 0 for byte. The mode argument is set to 0 if the data argument contains data to place in the blob. The mode is set to 1 if the data argument is a path to a file.

<?
//connect to database
if(!($dbLink = ifx_pconnect("[email protected]_srv1", "
leon", "secret"))
{
print("Unable to connect!<BR> ");
exit();
}
//create blob and add to array
$blob[] = ifx_create_blob(0, 0, "This is a message");
//insert message
$Query = "INSERT INTO message " .
"VALUES (3,'My Title', ?)";
if(!($result = ifx_query($Query, $dbLink, $blob))
{
print("Unable to insert message!<BR> ");
//print Informix error message
print(ifx_error() . "<BR> ");
print(ifx_errormsg() . "<BR> ");
}
//free result identifier
ifx_free_result($result);
//close connection
ifx_close($dbLink);
?>

integer ifx_create_char(string data)
The ifx_create_char function creates a character object. An identifier for the character object is returned.

boolean ifx_do(integer result)
The ifx_do function executes a query prepared with ifx_prepare. The result argument must be as returned by ifx_prepare.

string ifx_error()
Use ifx_error to fetch the error produced by the last query. The first character of the returned string is a flag reporting the type of condition. A space means no error. E is an error. N means no more data is available. W is a warning. A ? signals an unknown error condition. If anything other than a space is returned in the first character, the string will contain extra information, including an error code. See ifx_create_blob for an example of use.

string ifx_errormsg(integer error)
Use ifx_errormsg to fetch a description of an error given its code. This is the same numerical code returned by the ifx_error function. If no error code is supplied, the description of the last error is returned.

array ifx_fetch_row(integer result, integer position) array ifx_fetch_row(integer result, string position)
The ifx_fetch_row function returns a row from a result set after executing a select. The returned array will contain elements named in the query indexed by column names. If cursor type was set using IFX_SCROLL, then you may use the position argument. This can be an integer, or one of these strings: FIRST, NEXT, LAST, PREVIOUS, CURRENT. See ifx_prepare for an example of use.

array ifx_fieldproperties(integer result)
The ifx_fieldproperties function returns an array containing information about each column in a result set. The elements of the array are indexed by the column names. Each element contains a list of properties separated by semicolons. The parts of this string are type, length, precision, scale, and a flag for whether the column can be null. The type is one of the strings listed in ifx_fieldtypes, below.

array ifx_fieldtypes(integer result)
The ifx_fieldtypes function returns an array describing the type for eachcolumn in the result set. Possible values are SQLBOOL, SQLBYTES, SQLCHAR, SQLDATE, SQLDECIMAL, SQLDTIME, SQLFLOAT, SQLINT, SQLINT8, SQLINTERVAL, SQLLVARCHAR, SQLMONEY, SQLNCHAR, SQLNVCHAR, SQLSERIAL, SQLSERIAL8, SQLSMFLOAT, SQLSMINT, SQLTEXT, SQLUDTFIXED, SQLVCHAR. The returned array is indexed by the names of the columns.

boolean ifx_free_blob(integer blob)
The ifx_free_blob function deletes the specified blob from the database.

boolean ifx_free_char(integer character)
The ifx_free_char function deletes a character object from the database.

boolean ifx_free_result(integer result)
The ifx_free_result function frees memory associated with a result set. See ifx_pconnect for an example of use.

string ifx_get_blob(integer blob)
The ifx_get_blob function returns the contents of a blob.

string ifx_get_char(integer character)
The ifx_get_char function returns the contents of a character object.

array ifx_getsqlca(integer result)
The ifx_getsqlca function returns an array of the values in the sqlerrd struct from the underlying Informix API.

integer ifx_htmltbl_result(integer result, string options)
The ifx_htmltbl_result function prints an HTML table containing all the rows in the result set. The optional options argument will be placed inside the table tag. See ifx_pconnect for an example of use.

boolean ifx_nullformat(integer mode)
When mode is 0, ifx_nullformat will cause all null columns to be returned as empty strings. If mode is 1, they are returned as NULL, a four-character string.

integer ifx_num_fields(integer result)
The ifx_num_fields function returns the number of columns in the result set.

integer ifx_num_rows(integer result)
Use ifx_num_rows to get the exact number of rows already fetched for a result set. To get an approximate number of rows in a result set, use ifx_affected_rows.

integer ifx_pconnect(string database, string user, string password)
The ifx_pconnect function is similar to ifx_connect, except that connections are not closed until the Web server process ends. Persistent links remain available for subsequent connection attempts by other scripts.

<?
//connect to database
if(!($dbLink = ifx_pconnect("[email protected]_srv1", "leon", "secret"))
{
print("Unable to connect!<BR> ");
exit();
}
//treat blobs as varchars
ifx_textasvarchar(TRUE);
//get a record from the message table
$Query = "SELECT Title, Body FROM message " .
"WHERE ID = 3 ";
if(!($result = ifx_query($Query, $dbLink))
{
print("Unable to query message table!<BR> ");
}
//print results in HTML table
ifx_htmltbl_result($result);
//free result identifier
ifx_free_result($dbLink);
//close connection
ifx_close($dbLink);
?>

integer ifx_prepare(string query, integer link, integer cursor_type, array blob_id)
The ifx_prepare function parses a query but does not execute it. Otherwise it operates identically to ifx_query, described below. To execute the query, use ifx_do.

<?
//connect to database
if(!($dbLink = ifx_pconnect("[email protected]_srv1", "leon", "secret"))
{
print("Unable to connect!<BR> ");
exit();
}
//get message about PHP
$Query = "SELECT ID, Title FROM message " .
"WHERE Title like '%PHP%' ";
if(!($result = ifx_prepare($Query, $dbLink, IFX_SCROLL))
{
print("Unable to query message table!<BR> ");
}
if(ifx_affectedrows($result) 100)
{
//execute query
ifx_do($result);
//fetch each row, print a link
while($row = ifx_fetch_row($result, "NEXT"))
{
print("A HREF="get.php?id={$row["ID"]}">");
print("{$row["Title"]}/A><BR> ");
}
}
else
{
print("Too many results to display on one page.<BR> ");
}
//free result identifier
ifx_free_result($dbLink);
//close connection
ifx_close($dbLink);
?>

integer ifx_query(string query, integer link, integer cursor_type, array blob_id)
The ifx_query function executes a query and returns a result identifier, which most of the other Informix functions require. The link argument is as returned by ifx_pconnect, but if you leave it out, the last link established will be used. If the query is a select, you may use the IFX_SCROLL and IFX_HOLD constants for the cursor type. If performing an update or insert, you may use a ? in the query and match it to an entry in the blob_id argument. Each entry must be a value returned by ifx_create_blob. Selects that return blob columns will return blob identifiers by default, but you can override this functionality with ifx_textasvarchar. Note that both cursor_type and blob_id are optional. The ifx_query function will allow you to specify an array of blob identifiers for the third argument. See ifx_create_blob for an example of use.

boolean ifx_textasvarchar(integer mode)
Use ifx_textasvarchar to control how text blobs are returned in queries. If mode is 0, blob IDs are returned. If mode is 1, blob contents are returned. See ifx_pconnect for an example of use.

boolean ifx_update_blob(integer blob, string data)
The ifx_update_blob function changes the contents of a blob.

boolean ifx_update_char(integer character, string data)
The ifx_update_char function changes the contents of a character object.

ifxus_close_slob
You can use ifxus_close_slob as an alias for ifxus_free_slob.

integer ifxus_create_slob(integer mode)
Use ifxus_create_slob to create a slob object. The object identifier is returned. The modes listed may be combined with l operators.

integer ifxus_create_slob(integer mode)

boolean ifxus_free_slob(integer slob)
The ifxus_free_slob function deletes a slob object.

integer ifxus_open_slob(integer slob, integer mode)
Use ifxus_open_slob to get an identifier for an existing slob object. The modes listed may be combined with | operators.

string ifxus_read_slob(integer slob, integer bytes)
The ifxus_read_slob function returns data from the specified slob object. The bytes argument specifies the number of bytes to return.

integer ifxus_seek_slob(integer slob, integer mode, integer offset)
The ifxus_seek_slob function moves the current cursor position within a slob object. The mode argument controls where the offset is applied. If mode is 0, offset is applied to the beginning. If ode is 1, offset is applied to the current position. If mode is 2, offset is applied to the end of the lob object.

integer ifxus_tell_slob(integer slob)
The ifxus_tell_slob function returns the current position of a cursor inside a slob object.

integer ifxus_write_slob(integer slob, string data)
The ifxus_write_slob function writes data to an open slob object. The number of bytes written is returned.



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP Topics