How to tell if connection is successful or not

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
warriorforgod
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 11:16 am

How to tell if connection is successful or not

Post 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");
?>
 
 
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to tell if connection is successful or not

Post 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()
warriorforgod
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 11:16 am

Re: How to tell if connection is successful or not

Post 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.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to tell if connection is successful or not

Post by mikemike »

Can you post the code you have again?
warriorforgod
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 11:16 am

Re: How to tell if connection is successful or not

Post 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));
?>
 
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to tell if connection is successful or not

Post 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);
?>
warriorforgod
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 11:16 am

Re: How to tell if connection is successful or not

Post 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);
?>
 
 
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to tell if connection is successful or not

Post by mikemike »

is display_errors on?
warriorforgod
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 11:16 am

Re: How to tell if connection is successful or not

Post 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.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How to tell if connection is successful or not

Post by mikemike »

Heh, after all that your code was fine :wink: good luck
Post Reply