Common Database Connection programs

Source: Internet
Author: User
The following are several database connection programs collected at work and can be used to test the database. Access2003 Connection Program (asp): % dimdbpath, connstr, conndbpath # bjbaidu. mdbconnstrDRIVERMicrosoftAccessDriver (*. mdb); DBQserver. mappath (dbpath) SetconnServer. CreateObject (

The following are several database connection programs collected at work and can be used to test the database. Access 2003 Connection Program (asp): % dim dbpath, connstr, conn dbpath = "# bjbaidu. mdb "connstr =" DRIVER = Microsoft Access Driver (*. mdb); DBQ = "server. mappath (dbpath) Set conn = Server. createObject (

The following are several database connection programs collected at work and can be used to test the database.Access 2003 Connection Program (asp ):<%
Dim dbpath, connstr, conn
Dbpath = "# bjbaidu. mdb"
Connstr = "DRIVER = Microsoft Access Driver (*. mdb); DBQ =" & server. mappath (dbpath)
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. Open connstr
%>Access 2007 Connection Program (asp ):<%
Dim dbpath, connstr, conn
Dbpath = "123. accdb"
Connstr = "DRIVER = Microsoft Access Driver (*. mdb, *. accdb); DBQ =" & server. mappath (dbpath)
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. Open connstr
%>Access Connection (php ): /*
* Create An ADO connection
*/
$ Conn = @ new COM ("ADODB. Connection") or die ("ADO Connection faild .");
$ Connstr = "DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ =". realpath ("# bjbaidu. mdb ");
$ Conn-> open ($ connstr );
/*
* Create a record set
*/
$ Rs = @ new COM ("ADODB. RecordSet ");
$ Rs-> open ("select * from bj_link", $ conn, 1, 3 );
/*
* Read data cyclically
*/
While (! $ Rs-> eof ){
Echo $ rs-> fields ['title']-> Value;
Echo"
";
$ Rs-> movenext (); // move the record set pointer down
}
$ Rs-> close ();
?>Mysql connection (php ): Header ("Content-type: text/html; charset = UTF-8 ");
$ Mysql_server_name = "222.76.214.216"; // database server name
$ Mysql_username = "sunhillscn"; // username used to connect to the database
$ Mysql_password = "123"; // connection password
$ Mysql_database = "sunhillscn"; // Database Name

// Connect to the database
$ Conn = mysql_connect ($ mysql_server_name, $ mysql_username,
$ Mysql_password );

// SQL statement used to extract information from the table
$ Strsql = "select * from cnscms_article limit 5 ";
// Execute SQL query
$ Result = mysql_db_query ($ mysql_database, $ strsql, $ conn );
// Obtain the query result
$ Row = mysql_fetch_row ($ result );

Echo '';
Echo'



{
Echo'








{
Echo'




'; // Display the field nameEcho "\ n \ N ";For ($ I = 0; $ I \ N ";}Echo" \ N ";// Locate the first recordMysql_data_seek ($ result, 0 );// Retrieve records cyclicallyWhile ($ row = mysql_fetch_row ($ result )){Echo" \ N ";For ($ I = 0; $ I ';}Echo" \ N ";} Echo"
'.
Mysql_field_name ($ result, $ I );
Echo"
';
Echo "$ row [$ I]";
Echo'
\ N ";
Echo "";
// Release resources
Mysql_free_result ($ result );
// Close the connection
Mysql_close ();
?> For more database connection code, visit http://www.connectionstrings.com /.

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.