。
The Odbc_exec () function is used to execute SQL statements
$db _user= "Dbuser"; Define connection user Name
$db _pass= "Dbpass"; Connect the user's corresponding password
$DSN = "DSN"; Defining DSN Data sources
if (Odbc_connect ($DSN, $db _user, $db _pass))//Connect to ODBC data source
{
echo "Successfully connected to ODBC data source"; If the content is successfully exported
}
Else
{
echo "There was a problem connecting to ODBC!" "; If the output fails
}
Odbc_close_all (); To turn off all open connections
echo "All open ODBC connections have been turned off!" "; Output after function execution
See a more advanced connection to the host
$db _host= "server.mynetwork"; //define host name
$db _user= "Dbuser"; //defines the connection user name
$db _pass= "Dbpass"; //defines the user's password
$dsn = "DSN"; //defines DSN
$result =odbc_pconnect ($DSN, $db _user, $db _pass); // Open a persistent, valid ODBC connection
if ($result) //to determine the results
{
echo "Open a continuously valid connection"; //successfully performed output
}
echo "<br>" ;
if (Odbc_close ($result)) //attempt to close the connection
{
echo It's closed? "; //if the output is successfully closed
}
Else
{
echo cannot be turned off! "; //if the failed output
}
is turned off
Query Database Tutorial Save
Data source for connection
$my _sql= "select * from Usertable"; Defining SQL statements
$result =odbc_do ($myconn, $my _sql); Execute SQL statement
echo odbc_num_rows ($result);
echo "<table border=" 1 ">n";
echo "<tr>n";
echo "<td>id number </td>n";
echo "<td>name</td>n";
echo "<td>address</td>n";
echo "</tr>n";
while (Odbc_fetch_row ($result))
{
echo "<tr>n";
echo "<td>". Odbc_result ($result, 1). " </td>n ";
echo "<td>". Odbc_result ($result, 2). " </td>n ";
echo "<td>". Odbc_result ($result, 3). " </td>n ";
echo "</tr>n";
}
echo "</table>";
Some related
Odbc_free_result ($result); //frees memory occupied by executing SQL statements
Echo The memory occupied by the result set has been successfully released! ";
Odbc_rollback ($myconn) cancels all uncommitted operations
Odbc_commit ($myconn)//commits all uncommitted operations
Odbc_autocommit ($myconn, false); //prohibit automatic commit
Odbc_columnprivileges ($myconn, "Dbuser", "admin", "usertable", " Name "); //lists the columns and permissions for a given table
$result =odbc_columns ($myconn); //lists the names of the columns for the specified table
Echo Odbc_result_all ($result);