PHP connection to various database methods code memo

Source: Internet
Author: User
PHP provides two sets of functions connected to Oracle: ORA _ and OCI. The ORA _ function is somewhat outdated. OCI function updates are said to be better. The syntax is almost the same. Your PHP installation options should support both. PHP connection to MYSQL database code
$ Mysql_server_name = 'localhost'; // change it to your mysql database server.
$ Mysql_username = 'root'; // change the username of your mysql database.
$ Mysql_password = '000000'; // change the password of your mysql database.
$ Mysql_database = 'mycounter '; // change the name of your mysql database.

$ Conn = mysql_connect ($ mysql_server_name, $ mysql_username, $ mysql_password, $ mysql_database );
$ SQL = 'create DATABASE mycounter DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
';
Mysql_query ($ SQL );
$ SQL = 'create TABLE 'counter' ('id' INT (255) UNSIGNED NOT NULL AUTO_INCREMENT, 'count' INT (255) UNSIGNED NOT NULL DEFAULT 0, primary key ('id') TYPE = innodb ;';
Mysql_select_db ($ mysql_database, $ conn );
$ Result = mysql_query ($ SQL );
// Echo $ SQL;
Mysql_close ($ conn );
Echo "Hello! The database mycounter has been successfully created! ";

?>

PHP code for connecting to the ACCESS Database
$ Conn = new com ("ADODB. Connection ");
$ Connstr = "DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ =". realpath ("data/db. mdb ");
$ Conn-> Open ($ connstr );
$ Rs = new com ("ADODB. RecordSet ");
$ Rs-> Open ("select * from szd_t", $ conn, 1, 1 );
While (! $ Rs-> eof ){
$ F = $ rs-> Fields (1 );
Echo $ f-> value;
$ Rs-> MoveNext ();
}
?>
PHP connection to the ms SQL database code
1. install the SQL Server and add MSSQL extensions for PHP
2. use the following code to connect and test

$ MyServer = localhost; // host
$ MyUser = sa; // User name
$ MyPass = password; // password
$ MyDB = Northwind; // MSSQL database name

$ S = @ mssql_connect ($ myServer, $ myUser, $ myPass)
Or die (Couldnt connect to SQL Server on $ myServer );

$ D = @ mssql_select_db ($ myDB, $ s)
Or die (Couldnt open database $ myDB );

$ Query = SELECT TitleOfCourtesy ++ FirstName ++ LastName AS Employee;
$ Query. = FROM Employees;
$ Query. = WHERE Country = usa and Left (HomePhone, 5) = (206 );

$ Result = mssql_query ($ query );
$ NumRows = mssql_num_rows ($ result );

Echo. $ numRows. Row. ($ numRows = 1? : S). Returned;

While ($ row = mssql_fetch_array ($ result ))
{
Echo
  • . $ Row [Employee].
  • ;
    }

    ?>
    PHP connection to Oracle Database


    PHP provides two sets of functions connected to Oracle: ORA _ and OCI. The ORA _ function is somewhat outdated. OCI function updates are said to be better. The syntax is almost the same. Your PHP installation options should support both.

    Connection

    <? If ($ conn = Ora_Logon ("user @ TNSNAME", "password "))
    {Echo "SUCCESS! Connected to database \ n ";
    } Else
    {Echo "Failed:-(cocould not connect to database \ n ";}
    Ora_Logoff ($ conn );
    Phpinfo ();
    ?>

    The above code uses the Oracle database name, user name, and password defined by TNSNAME (specified in your tnsnames. ora file) to connect to the database. Based on successful connections, the ora_logon function returns a non-zero connection ID and stores it in the variable $ conn.

    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.