这是PHPinfo输出:
version.php
以下是代码:
$serverName = "X.X.X.X"; $connection = array( "UID"=>"UserID","PWD"=>"Password123","Database"=>"database_name"); $conn = sqlsrv_connect( $serverName,$connection); if ($conn === false) { $myfile3 = fopen("log.txt","w"); fwrite($myfile3,sqlsrv_errors()); fclose($myfile3); }; $tsql = "SELECT top 10 pName from products"; $stmt = sqlsrv_query( $conn,$tsql); $row = sqlsrv_fetch_array($stmt); $myfile4 = fopen("log.txt","w"); fwrite($myfile4,$row[0]); fclose($myfile4); sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn);
没有写入日志文件.即使我在fwrite($myfile3,“硬编码文本”)中硬编码文本;地方,没有什么是写出来的.
[ExtensionList] ;extension=PHP_MysqL.dll extension=PHP_MysqLi.dll extension=PHP_mbstring.dll extension=PHP_gd2.dll extension=PHP_gettext.dll extension=PHP_curl.dll extension=PHP_exif.dll extension=PHP_xmlrpc.dll extension=PHP_openssl.dll extension=PHP_soap.dll extension=PHP_pdo_MysqL.dll extension=PHP_pdo_sqlite.dll extension=PHP_imap.dll extension=PHP_tidy.dll extension=PHP_sqlsrv_7_nts_x64.dll ;extension=PHP_sqlsrv_7_ts_x64.dll
最后,我知道我不需要所有这些,但这些是我的ext文件夹中的4个dll.
PHP_sqlsrv_7_nts_x64.dll PHP_sqlsrv_7_nts_x86.dll PHP_sqlsrv_7_ts_x64.dll PHP_sqlsrv_7_ts_x86.dll
使用pdo:
$serverName = "(local)\sqlexpress"; /* Connect using Windows Authentication. */ try { $conn = new PDO( "sqlsrv:server=$serverName ; Database=AdventureWorks","",""); $conn->setAttribute( PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION ); } catch(Exception $e) { die( print_r( $e->getMessage() ) ); }
程序方式:
$serverName = "(local)\sqlexpress"; $connectionOptions = array("Database"=>"AdventureWorks"); /* Connect using Windows Authentication. */ $conn = sqlsrv_connect( $serverName,$connectionOptions); if( $conn === false ) die(sqlsrv_errors());