Creole/Propel/PHP MSSQL connection problem

Hi Everybody! I hope someone can help me.


I'm working on a php-propel-creole framework. I was using it with mysql with no problem at all. But now I need to change to mssql and when I try to connect to my bd in order to use the Peer objects I get the following error:



Fatal error: Uncaught exception 'SQLException' with message 'connect failed [Native Error: Database context changed to 'master'.] [User Info: Array]' in c:\apachefriends\xampp\php\pear\creole\drivers\mssql\MSSQLConnection.php:94 Stack trace: #0 c:\apachefriends\xampp\php\pear\creole\drivers\mssql\MSSQLConnection.php(94): MSSQLConnection::connect() #1 C:\apachefriends\xampp\php\pear\creole\Creole.php(243): MSSQLConnection->connect(Array, 0) #2 C:\apachefriends\xampp\htdocs\esic\codeBehind\esic.php(30): Creole::getConnection(Array) #3 C:\apachefriends\xampp\htdocs\esic\inc\main.php(46): include('C:\apachefriend...') #4 C:\apachefriends\xampp\htdocs\esic\index.php(28): include('C:\apachefriend...') #5 {main} thrown in c:\apachefriends\xampp\php\pear\creole\drivers\mssql\MSSQLConnection.php on line 94


The database I want to connect to is named registro_civil and the server is REGISTROCIVIL (it's the name of the computer). I configure the dsn as:


$dsn = array('phptype' => 'mssql',

             'hostspec' => 'REGISTROCIVIL',

             'username' => 'sa',

             'password' => '',

             'database' => 'registro_civil');


Is there any problem with this????


Any help will be appreciated. Thanks in advance.

Who is Participating?
Richard QuadlingSenior Software DeveloperCommented:
Some links ...

I suspect that the warning generates an error number. Your code will need to ignore this error number.

I don't use Creole, so I can't say for sure what the code should do.

Can you provide creole\drivers\mssql\MSSQLConnection.php - ideally the function containing line 94.

Maybe there is already some code to assist in filtering error conditions.
bethzycbAuthor Commented:
This is the function on creole\drivers\mssql\MSSQLConnection.php where the error is generated:

 function connect($dsninfo, $flags = 0)
        if (!extension_loaded('mssql') && !extension_loaded('sybase') && !extension_loaded('sybase_ct')) {
            throw new SQLException('mssql extension not loaded');

        $this->dsn = $dsninfo;
        $this->flags = $flags;
        $persistent = ($flags & Creole::PERSISTENT === Creole::PERSISTENT);

        $user = $dsninfo['username'];
        $pw = $dsninfo['password'];
        $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
        if (PHP_OS == "WINNT" || PHP_OS == "WIN32") {
            $portDelimiter = ",";
        } else {
            $portDelimiter = ":";
        if(!empty($dsninfo['port'])) {
                $dbhost .= $portDelimiter.$dsninfo['port'];
        } else {
                $dbhost .= $portDelimiter.'1433';
        $connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';

        if ($dbhost && $user && $pw) {
            $conn = @$connect_function($dbhost, $user, $pw);
        } elseif ($dbhost && $user) {
            $conn = @$connect_function($dbhost, $user);
        } else {
            $conn = @$connect_function($dbhost);
        if (!$conn) {
line 94----->            throw new SQLException('connect failed', mssql_get_last_message());
        if ($dsninfo['database']) {
            if (!@mssql_select_db($dsninfo['database'], $conn)) {
                throw new SQLException('No database selected');              
            $this->database = $dsninfo['database'];
        $this->dblink = $conn;        

Here, there is no try/catch code because from here the SQLException is thrown. Furthermore, it's the connection to the server which is not possible, and therefore it can't select ANY database at all, not even the "master" one. So I GUESS the error is the failure in the connection not the context changed issue.

I tried catching the error on the parts of code that call this MSSQLConnection.php script, but if I do so, I get no database selected.

The only thing I GUESS could be wrong might be the parameters the connect_function (mssql_connect) is receiving and those are: "server=REGISTROCIVIL,1433  user=sa password=". I don't know if the sintax SERVER,port (REGISTROCIVIL,1433) or the port number is being sent is correct.

Does anybody have any idea what's wrong?
Richard QuadlingSenior Software DeveloperCommented:
You will need the password for the connection. Unless you are using trusted connections, you may not get access.

The port number is OK and the default value.

The three @ signs in the lines above the exception, can you remove them. They are suppressing the error and allowing the exception to deal with it.

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

bethzycbAuthor Commented:
Thanks RQuadling, can you tell me, how do I know if I'm using trusted connections?
Richard QuadlingSenior Software DeveloperCommented:
Your SQL server admin will tell you if trusted connections are allowed.

In those cases, you normally don't supply a user name or a password.
bethzycbAuthor Commented:
Ehm... sorry but I'm newbie in sql server administration. I tried modifying security of my sqlserver and allowing windows nt ONLY authentication. I don't know if that allow me trusted connections :$ But after doing so, things keep the same, the connect fail is still there :(

Any idea?
bethzycbAuthor Commented:
After some workaround, I could make the server get connected.

What I did was:
- I changed the ntwdblib.dll of c:\windows\system32 to the one of version 2000.80.194.0 and deleted the one in c:\php

- I enabled trusted connections, modifying security in my sqlserver allowing Windows NT ONLY Authentication.

- I removed the PORT number from the dsn string used to get connected

And after all of this I could get connected.

NOTE: I didn't need to catch any error on the try/catch code.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.