Now we'll enumerate the common ODBC functions in PHP3:
Odbc_connect (Dns,user, pass);
Returns a connection number that returns 0 if the connection fails.
Odbc_pconnect (Dns,user,pass);
Special connections, the connection is not disconnected after the script is run. It is faster to connect the same DNS for the second time.
Odbc_commit (connection number);
Interrupts the thread that the connection is executing, returns true successfully, and returns false for failure.
Odbc_autocommit (connection number, 0/1);
When the parameter is 1 o'clock, all threads that are executing the connection are set to be automatically interrupted.
Odbc_do/odbc_exec (connection number, SQL statement);
Executes the SQL statement, returns a result number, and returns false if the operation fails.
Odbc_prepare (connection number, SQL statement);
Returns a result number, but does not execute the SQL statement. You can do this later with Odbc_execute (the result number).
Odbc_fetch_into (Result number, [number of records,] array);
Put a record of the result (omitted as the next record) into an array (starting from [0]), regardless of the type of the array.
Returns the position of the record in the result, such as false if the operation fails.
Odbc_fetch_row (result number, [record number]);
Move to a record (omitted as the next record), which can be read and written by Odbc_result.
Odbc_num_fields (result number);
Returns the total number of fields.
Odbc_num_rows (result number);
Returns the total number of records.
Odbc_result (Result number, field number/field name);
Returns the field for the field number/field name in the current record in the result.
Odbc_result_all (Result number, SQL statement);
Returns all query results and outputs in HTML table.
Odbc_field_name/odbc_field_type/odbc_field_len (Result number, field number);
Returns the field name/data type/Data length for this field.
Odbc_lonreaglen (Result number, length);
Sets the length of the field that returns the result, such as 0 to return all.
Odbc_free_result (result number);
Frees up memory when the query results in memory are not needed.
Odbc_cursor (result number);
Returns a pointer to the result.
Odbc_rollback
Odbc_close (connection number);
Closes the connection.
Odbc_close_all ();
Closes all connections.
A specific example of using PHP3 to manipulate an ODBC database.
DB is the DSN name for ODBC, 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 also be simplified to:
$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);
?>