Page 1 of 1

How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 11:36 am
by warriorforgod
I am using the following script to connect to a mssql 2005 database, however when I bring up the page nothing displays. I am a php newb so go easy on me.

Code: Select all

 
<?php
error_reporting(E_ALL);
$dbuser='username';
$dbname='database name';
$server='servername';
$connect = mssql_connect($server, $dbuser) or die (mysql_error());
mssql_select_db($dbname, $connect) or die (mysql_error());
echo("ConnectID: $numero<br>\n");
?>
 
 

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 12:01 pm
by mikemike
So far as this script goes $numero isn't set.

mssql_connect may very well not be connecting, in which case you're killing the script and calling mysql_error. Notice the obvious mistake here? You're connecting to a >MS< SQL server but trying to call >MY< SQL errors.

Have a read of mssql_min_message_severity()

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 1:57 pm
by warriorforgod
Ok. Changed the mysql to mssql and used the min_message_severity. Have tried all the options for this but still getting nothing displayed for error messages.

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 2:20 pm
by mikemike
Can you post the code you have again?

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 2:28 pm
by warriorforgod

Code: Select all

 
<?php
error_reporting(E_ALL);
$dbuser='username';
$dbname='database name';
$server='server';
$connect = mssql_connect($server, $dbuser) or die (mssql_min_message_severity(10));
mssql_select_db($dbname, $connect) or die (mssql_min_message_severity(10));
?>
 

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 2:54 pm
by mikemike
You're using it wrong, check the documentation.
http://php.net/mssql_min_message_severity

Try something like:

Code: Select all

<?php
error_reporting(E_ALL);
 
$dbuser='username';
$dbname='database name';
$server='server';
 
mssql_min_message_severity(10);
 
$connect = mssql_connect($server, $dbuser);
 
mssql_select_db($dbname, $connect);
?>

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 3:01 pm
by warriorforgod
Ok. Here is the new code. Still nothing showing up.

Code: Select all

 
<?php
error_reporting(E_ALL);
 
$dbuser='username';
$dbname='dbname';
$server='servername';
 
mssql_min_message_severity(10);
 
$connect = mssql_connect($server, $dbuser);
 
mssql_select_db($dbname, $connect);
?>
 
 

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 3:10 pm
by mikemike
is display_errors on?

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 3:18 pm
by warriorforgod
Seems that was the issue. Now I am getting Fatal error: Call to undefined function: mssql_connect().

So off to get that fixed. Thanks for all the help.

Re: How to tell if connection is successful or not

Posted: Tue Jun 02, 2009 3:21 pm
by mikemike
Heh, after all that your code was fine :wink: good luck