Phpodbc_connect () function description and instance code. Connect to the ODBCodbc_connect () function to connect to the ODBC data source. This function has four parameters: data source name, user name, password, and optional pointer type parameters. The function connecting to odbco to connect to ODBCodbc_connect () is used to connect to the ODBC data source. This function has four parameters: data source name, user name, password, and optional pointer type parameters.
Connect to odbc
The odbc_connect () function is used to connect to the odbc data source. This 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"; // password of the connected user
$ Dsn = "dsn"; // defines the dsn data source
If (odbc_connect ($ dsn, $ db_user, $ db_pass) // connect to the odbc data source
{
Echo "successfully connected to the odbc data source"; // if the output is successful
}
Else
{
Echo "an error occurred while connecting to odbc! "; // If the output fails
}
Odbc_close_all (); // close all opened connections
Echo "all open odbc connections have been closed! "; // Output content after the function is executed
View a more advanced connection to the host
$ Db_host = "server. mynetwork"; // defines the host name.
$ Db_user = "dbuser"; // define the connection user name
$ Db_pass = "dbpass"; // defines the user's password.
$ Dsn = "dsn"; // defines a dsn
$ Result = odbc_pconnect ($ dsn, $ db_user, $ db_pass); // open a valid odbc Connection
If ($ result) // judge the result
{
Echo "open a valid connection"; // The Output Content is successfully executed.
}
Echo"
";
If (odbc_close ($ result) // try to close the connection
{
Echo "disabled? "; // If the output content is disabled successfully
}
Else
{
Echo "cannot be closed! "; // If the output fails to be disabled
}
Query Database tutorials
Connect to the data source
$ My_ SQL = "select * from usertable"; // define an SQL statement
$ Result = odbc_do ($ myconn, $ my_ SQL); // execute an SQL statement
Echo odbc_num_rows ($ result );
Echo"
N ";Echo"
N ";Echo"
| ID number | N ";Echo"
Name | N ";Echo"
Address | N ";Echo"
N ";While (odbc_fetch_row ($ result )){Echo"
N ";Echo"
| ". Odbc_result ($ result, 1 )." | N ";Echo"
". Odbc_result ($ result, 2 )." | N ";Echo"
". Odbc_result ($ result, 3 )." | N ";Echo"
N ";}Echo"
";
Related
Odbc_free_result ($ result); // release the memory occupied by SQL statements.
Echo "the memory occupied by the result set has been successfully released! ";
Odbc_rollback ($ myconn) cancels all uncommitted operations
Odbc_commit ($ myconn) // submit all uncommitted operations
Odbc_autocommit ($ myconn, false); // disable automatic commit
Odbc_columnprivileges ($ myconn, "dbuser", "administrator", "usertable", "name"); // lists the columns and permissions of a given table
$ Result = odbc_columns ($ myconn); // lists the names of columns in the specified table.
Echo odbc_result_all ($ result );
The export ODBCodbc_connect () function is used to connect to the ODBC data source. This function has four parameters: data source name, user name, password, and optional pointer type parameters. Connect to odbc o...