Tengo el siguiente file de conexion llamado class.connection.php
Código PHP:
class clsConnnection{
public $m_connectionDGSDATA = null; // Conection argument
public function connection()
{
if(!stristr(PHP_OS, 'WIN'))
{
# PRODUCTION LINUX CONNECT ODBC
$strUser = "user"; // User
$strPass = "xxxx"; // Password
$strDB = "Database"; // DB Name
$this->m_connectionDGSDATA = new PDO("odbc:$strDB", $strUser, $strPass);
}else{
# PRODUCTION WINDOWS CONNECT PDO
$strServer = "172.16.yy.xx"; // Server
$strUser = "user"; // User
$strPass = "xxxx"; // Password
$strDB = "Database"; // DB Name
$this->m_connectionDGSDATA = new PDO("sqlsrv:Server=" . $strServer . ";Database=" . $strDB, $strUser, $strPass);
}
}
public function close(){
unset($this->m_connectionDGSDATA);
}
}
Código PHP:
require_once('class.connection.php'); // Call file that contain the class connection
class search{
public $conn;
public $strConnect;
public $strData;
public $result;
public $intNumRows;
public $CantRows;
public function __construct(){
$this->conn = new clsConnnection;
$this->conn->connection();
$this->strConnect = $this->conn->m_connectionDGSDATA;
$this->strConnect->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$this->result = array();
$this->CantRows = array();
}
public function loadWebsite(){
/* Query to the database that load all the website need for the combobox */
$strQuery = "SELECT [BackOffice_Dev].[dbo].[book].[id], [BackOffice_Dev].[dbo].[book].[host_name] FROM [BackOffice_Dev].[dbo].[book]";
/* Execute the query */
$this->strData = $this->strConnect->query( $strQuery );
/* Display record */
while($data = $this->strData->fetch(PDO::FETCH_ASSOC)){
$this->result[] = array('id' => $data['id'],
'host_name' => $data['host_name']);
}
return $this->result;
$this->conn->close();
}
}
Cita:
Creo que el error es por el driver sqlserver, pero lo tengo habilitado en el php.ini y ademas tengo los dll correspondientes en la carpeta de extensiones php. Los drivers se llaman: Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\wamp\www\mas\class\class.connection.php on line 22
PDOException: could not find driver in C:\wamp\www\mas\class\class.connection.php on line 22
PDOException: could not find driver in C:\wamp\www\mas\class\class.connection.php on line 22
-php_pdo_sqlsrv_54_ts.dll
-php_pdo_sqlsrv_54_nts.dll
Nota: Estoy utilizando WAMP !