-
-
$conn = new Com("ADODB.Connection"); //Instantiate a Connection object - $connstr = "provider=sqloledb;datasource=.;uid= Username;pwd=password;database=database;";
- $conn->Open($connstr);
- $rs = new Com("ADODB.Recordset"); //Instantiate a Recordcount object
- /*Use Example*/
- $rs->Open('select * from News where bigclassid = 59 And LeadPostil is null', $conn, 1, 1);
- $count = $rs->RecordCount; // bbs.it -home.org
- echo "Total {$count} records
";
- for($i = 0; $i < $count ; $i++){
Fields('Title')->Value);//Title
- $arr_result[$i]['Color'] = addslashes( $rs->Fields('titlecolor')->Value?$rs->Fields('titlecolor')->Value:'');//Title color
- $arr_result[$i]['WenHao '] = addslashes($rs->Fields('OtherText')->Value);//Document number
- }
-
Copy code
Method 2, odbc connection database
-
-
- $dbhost = '';
- $dbuser = ''; //Your mssql username
- $dbpass = ''; //Your mssql password
- $dbname = ''; //Your mssql library name
$connect=odbc_connect("Driver={SQL Server};Server=$dbhost;Database=$dbname","$dbuser ","$dbpass");
- /*Example test*/
- $sql="select * from content";
- $exec=odbc_exec($connect,$sql);
- while($row = (odbc_fetch_array($exec )))
- {
- $row['id'] //Get field value
- ...
- }
-
Copy code
Method 3, PHP built-in function connection:
Open the php.ini file on the server with php5 and apache. Remove the semicolon ";" in front of ;extension=php_mysql.dll.
Restart the apache server.
-
- $dbh=mysql_connect("hostname","user","password");
- mssql_select_db("mydb", $dbh);
- ?>
Copy code
Method 4, connect Access data method
-
- $db=$_SERVER['DOCUMENT_ROOT']."/PHP_ACCESS/include/#mydb.mdb"; //It is best to use $_SERVER['DOCUMENT_ROOT'] to get the path here
- $conn = new COM('ADODB.Connection') or die('can not start Active X Data Objects');
- $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= $db");
- $rs = $conn->Execute('SELECT * FROM contents order by id desc');
- while(!$rs->EOF)
- {
- echo $rs->Fields[ 'name']->Value;
- $rs->MoveNext();
- }
- /*Release resources*/
- $rs->Close();
- $conn->Close();
- $ rs = null;
- $conn = null;
Copy code
|