-
-
$conn = new Com("ADODB.Connection"); //Instantiate a Connection object
- $connstr = "provider=sqloledb;datasource=.;uid=sa;pwd=123456 ;database=jnold;";
- $conn->Open($connstr);
- $rs = new Com("ADODB.Recordset"); //Instantiate a Recordcount object
$rs->Open('select * from News where bigclassid = 59 And LeadPostil is null', $conn, 1, 1);
- $count = $rs->RecordCount;
- echo "There are {$count} items in total Record
";
- for($i = 0; $i < $count ; $i++){
- $arr_result[$i]['Title'] = addslashes($rs->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
2.ODBC connection mssql
-
-
$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 ");
- $sql="select * from content";
- $exec=odbc_exec($connect,$sql);
- while($row = (odbc_fetch_array($exec)))
- {
- $row['id' ] //Get field value
- ...
- }
-
Copy code
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_mssql.dll.
Just restart the apache server
Secondly: Apply the sp3 patch to the server database where sqlserver2000 is installed, because with the sp3 patch, port 1433 can be opened.
Finally, install the sqlserver2000 client tool on the web server
-
- $dbh=mssql_connect("192.168.12.124","sa","");
- mssql_select_db("mydb", $dbh);
- ?>
-
Copy code
This method often fails to connect. It seems to be a dll file version problem
4. Method to connect access data
-
- $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
5. Connect to MySQL method:
-
-
$database_connection=null;
$hostname="localhost";
- $database="5aart";
- $username="root";
- $password="1234";
- global $database_connection;
- $database_connection=mysql_connect($hostname,$username,$password) or die(mysql_error());
- mysql_query("set names 'gbk'");
- mysql_select_db( $database,$database_connection) or die(mysql_error());
-
Copy code
6. How to connect to SQLserver
-
- $dbhost = 'localhost';
- $dbuser = 'sa'; //Your mssql username
- $dbpass = '1234'; //Your mssql password
- $dbname = '0772fang'; //Your mssql library name
- $connect=odbc_connect("Driver={SQL Server};Server=$dbhost;Database=$dbname","$dbuser","$dbpass");
- $sql="update news_pk set ffnums=ffnums+1 where newsID='$ID'";
- $exec=odbc_exec($connect,$sql);
Copy code
|