how to display success message for connection to db?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iansane
Forum Commoner
Posts: 62
Joined: Sun Apr 18, 2010 1:26 pm

how to display success message for connection to db?

Post by iansane »

Hi,

I'm working with a form and database and having troubles. The main issue is that I'm getting a blank white page with no errors. How can I tell php to output errors to let me know if I'm connecting to the database or not.

I have this

Code: Select all

$con = mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
But the problem is that I have other issues that are giving me a blank page and I want to see a success message not just a failed message. At least that way I know for certain that the connection is being made.

I tried this

Code: Select all

if (!$con){
$message = "no connection";
}
else{
$message = "success";
}
echo $message;
But still get the blank page. no failed or success message.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: how to display success message for connection to db?

Post by AbraCadaver »

At the top:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
iansane
Forum Commoner
Posts: 62
Joined: Sun Apr 18, 2010 1:26 pm

Re: how to display success message for connection to db?

Post by iansane »

Thank you abracadaver! I'm assuming that over rides settings in the php.ini file? Before I reinstalled everything, my last installation was already putting out these types of errors but since upgrading to Ubuntu 10.04 and the latest Ubuntu version of php the errors went away. Also I found several php.ini files in doing a system wide search to find out where it was and I wasn't sure which one to edit.

This is great though. I'll just put it at the top of all my pages and remove it when a page is complete.
iansane
Forum Commoner
Posts: 62
Joined: Sun Apr 18, 2010 1:26 pm

Re: how to display success message for connection to db?

Post by iansane »

Well now my title is misleading. Sorry about that.

So anyway, once I got my dbopen.php and dbclose.php working (thanks to the error messages that show now) I just put

Code: Select all

$message = "success";
at the end of the open and close files and echo it out in the main file to make absolutely certain it didn't just freeze up somewhere and give me a blank page.
Post Reply