ODBC function of php3. Now we will list the commonly used ODBC functions in PHP3: odbc_connect (dns, user, pass); return a connection number; if the connection fails, return 0. Odbc_pconnect (dns, user, pass); special connection now we will list the ODBC functions commonly used in PHP3:
Odbc_connect (dns, user, pass );
Returns a connection number. if the connection fails, returns 0.
Odbc_pconnect (dns, user, pass );
Special connection. after the script is run, the connection is not closed. The second connection to the same dns is faster.
Odbc_commit (connection number );
The thread that interrupts the connection. if the connection is successful, True is returned. if the connection fails, False is returned.
Odbc_autocommit (connection number, 0/1 );
When the parameter is set to 1, all threads that are executing the connection are set to automatic interruption.
Odbc_do/odbc_exec (connection number, SQL statement );
Execute the SQL statement and return a result number. if the operation fails, false is returned.
Odbc_prepare (connection number, SQL statement );
Returns a result number without executing an SQL statement. You can use odbc_execute (the result number) for subsequent execution.
Odbc_fetch_into (result number, [number of records,] array );
Place a record of the result (omitted as the next record) into an array (starting from [0]) regardless of the array type.
Returns the position of the record in the result. if the operation fails, false is returned.
Odbc_fetch_row (result number, [number of records]);
Move to a record (omitted as the next record), which can be read and written by odbc_result.
Odbc_num_fields (result number );
Total number of returned fields.
Odbc_num_rows (result number );
Total number of returned Records.
Odbc_result (result number, Field Number/field name );
This field number/field name in the current record in the returned result.
Odbc_result_all (result number, SQL statement );
Return all query results and output them in an html table.
Odbc_field_name/odbc_field_type/odbc_field_len (result number, Field number );
The field name, data type, and data length of the field are returned.
Odbc_lonreaglen (result number, length );
Set the length of the returned fields. if the length is 0, all fields are returned.
Odbc_free_result (result number );
Release the memory when no query results in the memory are required.
Odbc_cursor (result number );
Returns a pointer pointing to the result.
Odbc_rollback
Odbc_close (connection number );
Close the connection.
Odbc_close_all ();
Close all connections.
A specific example of using PHP3 to manipulate ODBC databases.
Db is the dsn name of odbc, and tab1 is the table name
Echo "ODBC Samples "."
";
$ Connection_ID = odbc_connect ("db ","","");
$ Result_ID = odbc_exec ($ Connection_ID, "Select * from tab1 ");
$ I = 1;
$ FldCount = odbc_num_fields ($ Result_ID );
Echo "";
While (odbc_fetch_row ($ Result_ID, $ I) <> 0)
{
Echo "";
For ($ j = 1; $ j <= $ fldCount; $ j ++)
{
Echo "". $ I ."";
Echo "". odbc_result ($ Result_ID, $ j )."";
}
Echo"
";
$ I = $ I + 1;
}
Echo "";
?>
In fact, the query process can be simplified:
$ Connection_ID = odbc_connect ("db ","","");
$ Result_ID = odbc_exec ($ Connection_ID, "Select * from tab1 ");
$ FldCount = odbc_num_fields ($ Result_ID );
Odbc_result_all ($ Result_ID );
?>
Odbc_connect (dns, user, pass); returns a connection number. if the connection fails, 0 is returned. Odbc_pconnect (dns, user, pass); special connection...