|
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.77">
2.1. Quick Overviewlibdbi uses a plugin system that allows various databases to be supported simultaneously, and can dynamically load or unload drivers that are supplied by libdbi or a third party. The library is initiallized by calling dbi_initialize and a connection instance is started by calling either dbi_conn_new or both dbi_driver_open and dbi_conn_open. The connection's options (username, password, hostname, etc.) are set with dbi_conn_set_option and dbi_conn_set_option_numeric. Once all options are set, dbi_conn_connect will connect to the database, waiting to handle a dbi_conn_query. After a successful query, you can retrieve rows with dbi_result_first_row, dbi_result_last_row, dbi_result_prev_row, dbi_result_next_row, and dbi_result_seek_row. There are two methods for fetching field data, and two ways to perform each method. You can either "pull" the data from DBI using the dbi_result_get_* family of functions, or have DBI automatically "push" the data into predefined variables with the dbi_result_bind_* family of functions. Pulling the data from the database can be done with one of the "get" functions such as dbi_result_get_long or dbi_result_get_string, which simply return the data in the field you asked for. You can also get more than one field at a time with dbi_result_get_fields, which uses a printf-like syntax. If you want DBI to automatically fill your program's variables with field values whenever a new row is fetched, you can "bind" fields to your variables. Bindings are set up with dbi_result_bind_long, dbi_result_bind_string, and the rest of the bind family of functions. Like the associated "get" function, you can set up multiple bindings at once with the dbi_result_bind_fields function. Caveats:
dbi_result_next_row and the other row-seeking functions will return zero when there are no more rows available. Before the next database operation is performed, you must call dbi_result_free. Before the program terminates, the connection must be disconnected and unloaded with dbi_conn_close and libdbi must be unloaded with dbi_shutdown. |