PHP ODBC database link function library

Source: Internet
Author: User
Tags dsn odbc stmt

Open Data links (Open database Connectivity,odbc) are a common interface for linked databases. ODBC is the Microsoft-led database link standard, the implementation environment is also the most mature Microsoft's system. In Unix systems, it is common to use the ODBC interface provided by other vendors, and some UNIX vendors provide their own ODBC interfaces (such as SUN has ODBC for Solaris).
ODBC and database queries use the SQL language, which is the same as most database queries, making it easy to communicate with a variety of databases. Of course, through the ODBC interface, the backend database does not necessarily have to be a DBMS for this large database system, it can also be a table (such as Microsoft Access), or a spreadsheet (such as Microsoft Excel).

Odbc_autocommit: Switch automatic change function.
Odbc_binmode: Configure the binary data processing mode.
Odbc_close: Turn off ODBC links.
Odbc_close_all: Close all ODBC links.
Odbc_commit: Change ODBC database.
Odbc_connect: Link to ODBC database.
Odbc_cursor: Gets the cursor name.
Odbc_do: Execute SQL directives.
Odbc_exec: Execute SQL directives.
Odbc_execute: Executes preset SQL directives.
Odbc_fetch_into: Gets the specified column returned.
Odbc_fetch_row: Get back a column.
Odbc_field_name: Gets the field name.
Odbc_field_type: Gets the field data type.
Odbc_field_len: Gets the field data length.
Odbc_free_result: Releases the memory of the returned data.
Odbc_longreadlen: Configures the maximum value of the returned column.
Odbc_num_fields: Gets the number of fields.
Odbc_pconnect: Long-term link to ODBC database.
Odbc_prepare: Presets SQL directives.
Odbc_num_rows: Gets the number of returned columns.
Odbc_result: Obtain return information.
Odbc_result_all: Returns HTML tabular data.
Odbc_rollback: Undo current transaction.
Odbc_setoption: Adjust the ODBC configuration.

Odbc_autocommit switch automatic change function.
Syntax: int odbc_autocommit (int connection_id, int [onoff]);
return value: Integer
Function Type: Database function
Content Description: This function is used to turn on or off the Automatic Update (AUTO-COMMIT) feature. Parameter connection_id is the ID value of the ODBC link. Parameter onoff can be omitted, the table turns on or off auto change, the default value is on, and off when you want to close. The return value is the current automatic update status and returns True if the Automatic Update feature is turned on, or false if the Automatic Update feature is turned off.
Reference: Odbc_commit () Odbc_rollback ()

Odbc_binmode configures the binary data processing mode.
Syntax: int odbc_binmode (int result_id, int mode);
return value: Integer
Function Type: Database function
Description: This function is used to configure the processing of binary data return. The types of data affected by this function are BINARY, VARBINARY and LongVarBinary. The parameter result_id to the returned ID value, and if set to 0, the program configures a new ID value.

Parameter mode is a binary processing method configured with the following values

ODBC_BINMODE_PASSTHRU returns binary data
Odbc_binmode_return turn to 16 to return
Odbc_binmode_convert turn to string data return

Note: If you use Odbc_fetch_into (), Odbc_binmode_passthru will lead to the return string value to be empty (empty). and return data maximum treatment  The default size is 4,096-bit group, to return more information to use Odbc_longreadlen ().
Reference: Odbc_fetch_into () Odbc_longreadlen ()

Odbc_close closes the ODBC link.
Syntax: void odbc_close (int connection_id);
return value: None
Function Type: Database function
Description: This function is used to close the link to the ODBC database. Parameter connection_id is an ODBC link code ID value. You cannot close a link if you are executing transactions.

Odbc_close_all closes all ODBC links.
Syntax: void Odbc_close_all (void);
return value: None
Function Type: Database function
Content Description: This function is used to turn off all links to ODBC databases. As with Odbc_close (), you cannot close a link if you are performing a transactions. You do not need to use any parameters with this function.

Odbc_commit changes the ODBC database.
Syntax: int odbc_commit (int connection_id);
return value: Integer
Function Type: Database function
Content Description: This function is used to change (commit) an ODBC database. Parameter connection_id is the ID value of the ODBC link. This function is not required if a configuration odbc_autocommit () is used to automatically alter the database.

Odbc_connect links to ODBC databases.
Syntax: int odbc_connect (string dsn, string user, string password, int [cursor_type]);
return value: Integer
Function Type: Database function
Content Description: This function is used to link to the ODBC database, the return value is the link's code ID value. The parameter DSN is the data source name (data Sources name). Parameter user and password are linked accounts and passwords respectively. The parameter cursor_type is usually omitted, its value is sql_cur_use_if_needed, Sql_cur_use_odbc, Sql_cur_use_driver and sql_cur_default etc. four kinds. When using complex data access, there may be similar "cannot open a cursor on a stored procedure this has anything other than a single SELECT statement in it Error message string, you can avoid it if you set the value of the parameter Cursor_type to SQL_CUR_USE_ODBC.
Reference: Odbc_pconnect ()

Odbc_cursor gets the cursor name.
Syntax: string odbc_cursor (int result_id);
return value: String
Function Type: Database function
Content Description: This function is used to obtain an open ODBC database cursor (cursor). Parameter connection_id is an ODBC link code ID value. Returns the name string for the cursor.

ODBC_DO executes the SQL instructions.
Syntax: int odbc_do (int connection_id, string query);
return value: Integer
Function Type: Database function
Content Description: This function is used to execute SQL query directives. Parameter connection_id is an ODBC link code ID value. parameter query is the command you want to execute. The return value is a result ID value.
Reference: Odbc_prepare () Odbc_execute () odbc_exec ()

Odbc_exec executes the SQL instructions.
Syntax: int odbc_exec (int connection_id, string query);
return value: Integer
Function Type: Database function
Content Description: This function is used to execute SQL query directives. Parameter connection_id is an ODBC link code ID value. parameter query is the command you want to execute. The return value is a result ID value.
Reference: Odbc_prepare () Odbc_execute () Odbc_do ()

Odbc_execute executes the preset SQL directives.
Syntax: int odbc_execute (int result_id, array [Parameters_array]);
return value: Integer
Function Type: Database function
Content Description: This function is used to perform the query command preset in 4.36.20 odbc_prepare (). Parameter result_id the ODBC return ID value. Parameter parameters_array are usually omitted.

Usage examples
<?php
$conn =odbc_connect ("MyDB", "" "," ");
$stmt = Odbc_prepare ($conn, "INSERT into MyTable (Jor_from, jor_to) ValueS (' $from ', ' $to ');";
if (!odbc_execute ($stmt)) {
echo "Error";
}
Odbc_close ($conn);
?>
Reference: Odbc_prepare () odbc_exec () Odbc_do ()

Odbc_fetch_into gets the specified column returned.
Syntax: int odbc_fetch_into (int result_id, int [rownumber], array result_array);
return value: Integer
Function Type: Database function
Description: This function is used to get the return column of Query and put in the array data. Parameter result_id the ODBC return ID value. Parameter RowNumber to the specified get column (row). The array parameter is result_array as an array of data to get the column, usually preceded by the "&" symbol. Examples provided by vbhunt@silverfox.com, for example (27-sep-1998)
$cols = Odbc_fetch_into ($QueryID, $RowNum, & $YourArray);

Odbc_fetch_row gets returned a column.
Syntax: int odbc_fetch_row (int result_id, int [row_number]);
return value: Integer
Function Type: Database function
Description: This function is used to get a column of Query's return data. Parameter result_id the ODBC return ID value. Parameter RowNumber can be omitted for the specified get column (row).

Usage examples
<?php
$conn = Odbc_connect ("WebDB", "" "," ");
$query = "Select User, Idno";
$query. = "from UserInfo";
$result _id = Odbc_do ($conn, $query);
while (Odbc_fatch_row ($result _id)) {
$user = Odbc_result ($result _id, 1);
$idno = Odbc_result ($result _id, 2);
echo $user. " The ID card size is ". $idno." <br>n ";
}
Odbc_close ($conn);
?>

Odbc_field_name Gets the field name.
Syntax: string odbc_fieldname (int result_id, int field_number);
return value: String
Function Type: Database function
Description: This function is used to get the field name of the return data of Query. Parameter result_id the ODBC return ID value. Parameter Field_number to the specified field with a starting value of 1.

Odbc_field_type Gets the field data type.
Syntax: string odbc_field_type (int result_id, int field_number);
return value: String
Function Type: Database function
Description: This function is used to get the field data type for Query's return data. Parameter result_id the ODBC return ID value. Parameter Field_number to the specified field with a starting value of 1.

Odbc_field_len Gets the field data length.
Syntax: int odbc_field_len (int result_id, int field_number);
return value: Integer
Function Type: Database function
Description: This function is used to get the field data length for Query's return data. Parameter result_id the ODBC return ID value. Parameter Field_number to the specified field with a starting value of 1.

Odbc_free_result releases the memory of the returned data.
Syntax: int odbc_free_result (int result_id);
return value: Integer
Function Type: Database function
Description: This function can be used to release the memory used to return data, usually in the case of low system memory resources need to use. Parameter result_id the ODBC return ID value. The return value is always true.

Odbc_longreadlen configuration returns the maximum value for the column.
Syntax: int odbc_longreadlen (int result_id, int length);
return value: Integer
Function Type: Database function
Content Description: This function is used to configure the maximum data values for the returned columns. Parameter result_id the ODBC return ID value. Parameter length is the length of the value to be configured, if this parameter is set to 0, the expression is not limited to length.

Odbc_num_fields gets the number of fields.
Syntax: int odbc_num_fields (int result_id);
return value: Integer
Function Type: Database function
Content Description: This function is used to get the number of fields returned data. Parameter result_id the ODBC return ID value. Returns-1 if an error occurs.

Odbc_pconnect long links to ODBC databases.
Syntax: int odbc_pconnect (string dsn, string user, string password, int [cursor_type]);
return value: Integer
Function Type: Database function
Content Description: This function is used to keep links to the ODBC database for a long time, even if the PHP program ends, the link still exists, the return value is the link's code ID value. This heavy-responsibility system for linking can speed up the link. The parameter DSN is the data source name (data Sources name). Parameter user and password are linked accounts and passwords respectively. Parameter cursor_type are usually omitted.
Reference: Odbc_connect ()

Odbc_prepare to preset SQL directives.
Syntax: int odbc_prepare (int connection_id, string query_string);
return value: Integer
Function Type: Database function
Content Description: This function is used to configure SQL query directives. Parameter result_id the ODBC return ID value. The parameter query_string is the preset instruction.
Reference: Odbc_execute ()

Odbc_num_rows gets the number of returned columns.
Syntax: int odbc_num_rows (int result_id);
return value: Integer
Function Type: Database function
Content Description: This function is used to get the number of returned columns. Parameter result_id the ODBC return ID value. Returns-1 if an error occurs.

Odbc_result obtain return information.
Syntax: string odbc_result (int result_id, mixed field);
return value: String
Function Type: Database function
Content Description: This function is used to obtain the returned data. Parameter result_id the ODBC return ID value. The parameter field can be a numeric type, representing the specified field ordinal (starting from 1), or a string type, for the specified field name.

Odbc_result_all returns HTML tabular data.
Syntax: int odbc_result_all (int result_id, string [format]);
return value: Integer
Function Type: Database function
Description: This function is used to convert the obtained data into an HTML table (table) format. Parameter result_id the ODBC return ID value. The parameter format can be omitted as a special configuration value for the table. The return value is the number of rows.

Usage examples
<?php
$conn = Odbc_connect ("WebDB", "" "," ");
$query = "Select item, Price";
$query. = "from UserInfo";
$result _id = Odbc_do ($conn, $query);
Odbc_result_all ($result _id, "Border=1 width=50%");
Odbc_close ($conn);
?>

Odbc_rollback undo the current transaction.
Syntax: int odbc_rollback (int connection_id);
return value: Integer
Function Type: Database function
Description: This function cancels the modifications made to the database by the ODBC transaction processing (transaction). Returns true if successful, otherwise returns false.

Odbc_setoption to adjust the ODBC configuration.
Syntax: int odbc_setoption (int id, int function, int option, int param);
return value: Integer
Function Type: Database function
Content Description: This function is used to adjust the ODBC configuration value. The parameter ID does not necessarily refer to connection_id,sqlsetconnectoption () to connection_id, or result_id if SQLSetStmtOption (). The parameter function value is 1 table SQLSetConnectOption (), and if 2 is SQLSetStmtOption (). Parameter option is the configured option. Parameter param is a configuration value.

Usage examples
?
Example one: The configuration is autocommit, that is, the same as Odbc_autocommit ($conn, True).
The third parameter value is 102 table Sql_autocommit.
The fourth parameter value is 1 table sql_autocommit_on.
Odbc_setoption ($conn, 1, 102, 1);
Example two: Configure Query time
Third parameter 0 table Sql_query_timeout
The fourth parameter is the longest execution time, and this example is set to 30 seconds.
$result = Odbc_prepare ($conn, $sql);
Odbc_setoption ($result, 2, 0, 30);
Odbc_execute ($result);
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.