如何让MSSQL与WAMP一起使用?

时间:2015-04-07 13:08:10

标签: php sql-server wamp

我已经尝试了一些我可能想到的让MSSQL与WAMP一起工作的东西。这是我的代码

<?php
$database = "appas";
$conn = new PDO( "sqlsrv:server=(IP) ; Database = $database", "sa1", "Password02");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 1 );

$query = 'select * from user';

// simple query
$stmt = $conn->query( $query );
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
   print_r( $row['first'] ."\n" );
}

echo "\n........ query for a column ............\n";

// query for one column
$stmt = $conn->query( $query, PDO::FETCH_COLUMN, 1 );
while ( $row = $stmt->fetch() ){
   echo "$row\n";
}

echo "\n........ query with a new class ............\n";
$query = 'select * from user order by last';
// query with a class
class cc {
   function __construct( $arg ) {
      echo "$arg";
   }

   function __toString() {
      return $this->DepartmentID . "; " . $this->Name . "; " . $this->GroupName;
   }
}

$stmt = $conn->query( $query, PDO::FETCH_CLASS, 'cc', array( "arg1 " ));

while ( $row = $stmt->fetch() ){
   echo "$row\n";
}

echo "\n........ query into an existing class ............\n";
$c_obj = new cc( '' );
$stmt = $conn->query( $query, PDO::FETCH_INTO, $c_obj );
while ( $stmt->fetch() ){
   echo "$c_obj\n";
}

$stmt = null;
?>

我收到此错误

( ! ) Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\wamp\www\Register\configdb.php on line 3
( ! ) PDOException: could not find driver in C:\wamp\www\Register\configdb.php on line 3
Call Stack
#   Time    Memory  Function    Location
1   0.0004  255760  {main}( )   ..\configdb.php:0
2   0.0004  256608  __construct ( ) ..\configdb.php:3

我不知道它为什么找不到驱动程序 - 我认为安装了DLL。如果有人知道我的问题,或者可以在WAMP 2.5中链接适当的MSSQL安装指南,我真的很想抓住这里的吸管。

http://imgur.com/8T4TasB

0 个答案:

没有答案