• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
connecting to mssql

#1
I was working with mysql with wamp and my coworker decided to work in mssql (I know bad communications but that's another story). We are at the point where I need my end to talk to his and we are having trouble with the connection.

His Stuff
Code:
try
{
   $conn = new PDO('sqlsrv:Server=192.168.1.1; Database=DBName',NULL, NULL);
   $conn ->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(PDOException $ex)
{
   die( 'Error connecting to SQL Server: '.$ex.'.');
}
echo 'connected to SQL Server\n';

My Stuff trying to connect to his
Code:
$db['default'] = array(
       'dsn'   => '',
       'hostname' => '192.168.1.1',
       'username' => '',
       'password' => '',
       'database' => 'DBName',
       'dbdriver' => 'pdo',
       'dbprefix' => '',
       'pconnect' => FALSE,
       'db_debug' => (ENVIRONMENT !== 'production'),
       'cache_on' => FALSE,
       'cachedir' => '',
       'char_set' => 'utf8',
       'dbcollat' => 'utf8_general_ci',
       'swap_pre' => '',
       'compress' => FALSE,
       'encrypt' => FALSE,
       'stricton' => FALSE,
       'failover' => array()
);

using his stuff on his test page, things connect but as I add his DB calls to my codeigniter page, things breaks. So we know the server is talking to my computer but I am using it wrong with codeigniter. please help.

I get error 42s02/208
[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid Object Name 'tbl_test'.
SELECT * FROM tbl_test
Reply

#2
Well, first of all, NULL is not the same as an empty string, so that could be a possible cause for being unable to connect.

However, the error message that you're showing is completely unrelated. In fact, that error message alone proves that you are already connected. There's something confusing about it though - ODBC mentioned in there? Is that really an error message emitted by PDO?

P.S.: Moving this thread to "General Help".
Reply

#3
NULL NULL works when using his test page so we know MSSQL server is ok with it. I also was of the opinion that we were in the database but failing to find the table. I was confused with the ODBC message since I was using PDO, I know we had to install ODBC drivers/exe per MS instructions but I'm not sure how it is utilized.
Reply

#4
Have you tried something like this?

PHP Code:
$db['default'] = array(
       
'dsn'   => 'sqlsrv:Server=192.168.1.1; Database=DBName',
       
'hostname' => '',
       
'username' => null,
       
'password' => null,
       
'database' => '',
       
'dbdriver' => 'pdo',
       
'dbprefix' => '',
       
'pconnect' => FALSE,
       
'db_debug' => (ENVIRONMENT !== 'production'),
       
'cache_on' => FALSE,
       
'cachedir' => '',
       
'char_set' => 'utf8',
       
'dbcollat' => 'utf8_general_ci',
       
'swap_pre' => '',
       
'compress' => FALSE,
       
'encrypt' => FALSE,
       
'stricton' => FALSE,
       
'failover' => array()
); 

I don't really see how you could have used the configuration you posted without receiving 'PDO: Invalid or non-existent subdriver', unless you were just trying to use his PDO code directly in your CI project.

As far as I know, the "[ODBC Driver 11 for SQL Server]" part of the error message is indicating the client used to connect to the server. The "Microsoft Drivers for PHP for SQL Server" use Microsoft ODBC Driver 11 for SQL Server to handle the communication with SQL Server. This appears to be the same whether you use SQLSRV or PDO_SQLSRV.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.