Now let's enumerate the ODBC functions commonly used in PHP3:
Odbc_connect (Dns,user, pass);
Returns a connection number that returns 0 if the connection fails.
Odbc_pconnect (Dns,user,pass);
Special connection, the connection does not disconnect after the script finishes running. The second time you connect the same DNS is faster.
Odbc_commit (connection number);
Interrupts the thread that the connection is executing, returns true successfully, and the failure returns false.
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. Can be executed 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 the array (starting with [0]), regardless of the type of the array.
Returns the position of the record in the result, or false if the operation failed.
Odbc_fetch_row (result number, [record number]);
Moves 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 of 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 them in an 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 for all returns.
Odbc_free_result (result number);
Frees memory when no in-memory query results are required.
Odbc_cursor (result number);
Returns a pointer to the result.
Odbc_rollback
Odbc_close (connection number);
Close the connection.
Odbc_close_all ();
Close all connections.
A concrete example of using PHP3 to manipulate ODBC databases.
DB is an ODBC DSN name, 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);
?>
http://www.bkjia.com/PHPjc/532090.html www.bkjia.com true http://www.bkjia.com/PHPjc/532090.html techarticle Now let's enumerate the ODBC functions commonly used in PHP3: Odbc_connect (Dns,user, pass); Returns a connection number that returns 0 if the connection fails. Odbc_pconnect (Dns,user,pass); Special connection ...