PHP odbc_connect () function description and instance code

Source: Internet
Author: User

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);  

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.