?
Solved

Creole/Propel/PHP MSSQL connection problem

Posted on 2006-04-26
7
Medium Priority
?
744 Views
Last Modified: 2013-12-12
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.

Beth
0
Comment
Question by:bethzycb
  • 4
  • 3
7 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 1500 total points
ID: 16551114
Some links ...

http://www.experts-exchange.com/Programming/Q_21406057.html

http://www.hummingbird.com/support/dirs/genio/tech6.html?cks=y


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.
0
 

Author Comment

by:bethzycb
ID: 16553433
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?
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16553484
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.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:bethzycb
ID: 16561950
Thanks RQuadling, can you tell me, how do I know if I'm using trusted connections?
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16562014
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.
0
 

Author Comment

by:bethzycb
ID: 16563713
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?
0
 

Author Comment

by:bethzycb
ID: 16564499
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question