Connect to odbc The odbc_connect () function is used to connect to odbc data sources. The function has four parameters: data source name, user name, password, and optional pointer type parameters.
The odbc_exec () function is used to execute sql statements
$ db_user = "dbuser"; / / define the connection user name $ db_pass = "dbpass"; / / connect to the user's corresponding password $ dsn = "dsn"; / / define dsn data source if (odbc_connect ($ dsn, $ db_user, $ db_pass)) // connect odbc data source { echo "successfully connected to odbc data source"; / / If successful output content } else { echo "problem connecting to odbc!"; // if the output failed }
odbc_close_all (); // Close all open connections echo "all open odbc connections have been closed!"; / / output function after the implementation of the function
Look at a more advanced host connection
$ db_host = "server.mynetwork"; / / define the host name $ db_user = "dbuser"; / / define the connection user name $ db_pass = "dbpass"; / / define the user's password $ dsn = "dsn"; // Define dsn $ result = odbc_pconnect ($ dsn, $ db_user, $ db_pass); // Open persistent odbc connection if ($ result) / / to determine the results { echo "Open a persistent connection"; / / Successful implementation of the output } echo "<br>"; if (odbc_close ($ result)) // try to close the connection { echo "closed?"; // if the output is successfully closed } else { Echo "can not be closed!"; / / If the output fails to close the output } Query database tutorial save
odbc_free_result ($ result); / / Release the memory used to execute sql statement echo "has successfully released the result set occupied memory!"; odbc_rollback ($ myconn) Cancel all uncommitted operations odbc_commit ($ myconn) // Submit all uncommitted operations odbc_autocommit ($ myconn, false); // Disable automatic commit odbc_columnprivileges ($ myconn, "dbuser", "admin", "usertable", "name"); // List the columns and permissions for the given table $ result = odbc_columns ($ myconn); // Lists the names of the columns of the specified table echo odbc_result_all ($ result);
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.