Home > Article > Backend Development > Example of PHP using ODBC to connect to the database
This article mainly introduces the method of using PHP to connect to the database using ODBC, covering the basic skills of using PHP to operate the database using ODBC. I hope to be helpful. The example in this article describes how PHP uses ODBC to connect to the database. Share it with everyone for your reference.
The specific implementation method is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP and ODBC: XHTML Example 1</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <?php $conn = odbc_connect( "DRIVER={MySQL ODBC 3.51 Driver};Server=localhost;Database=phpodbcdb", "username", "password"); if (!($conn)) { echo "<p>Connection to DB via ODBC failed: "; echo odbc_errormsg ($conn ); echo "</p>\n"; } $sql = "SELECT 1 as test"; $rs = odbc_exec($conn,$sql); echo "<table><tr>"; echo "<th>Test</th></tr>"; while (odbc_fetch_row($rs)) { $result = odbc_result($rs,"test"); echo "<tr><td>$result</td></tr>"; } odbc_close($conn); echo "</table>"; ?> </body> </html>
Related recommendations:
php database class is suitable for mysql sql service
Ultra-light PHP Database toolkit
The above is the detailed content of Example of PHP using ODBC to connect to the database. For more information, please follow other related articles on the PHP Chinese website!