Page 1 of 1
Successful data
Posted: Mon Jul 31, 2006 9:32 am
by mohson
Code: Select all
/*Connecting, selecting database*/
$link = mysql_connect("xxxxx", "xxxx", "xxxx")
or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");
Can someone show me how to update this code to include a message stating that the dtaabase was successfully loaded?
Posted: Mon Jul 31, 2006 9:35 am
by GM
If the script gets past this point then the database has been loaded successfully - if there were some problem, the die("message") statements would be executed and the script will stop working.
So you could simply add an echo on the next line:
Code: Select all
/*Connecting, selecting database*/
$link = mysql_connect("xxxxx", "xxxx", "xxxx")
or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");
/* At this point, if the script is still executing, then the database has been loaded successfully. */
echo '<BR \>Database Selected';
Posted: Mon Jul 31, 2006 9:44 am
by RobertGonzalez
I just posted this in a thread yesterday...
Code: Select all
<?php
define('DB_USER', 'user'); // USE YOUR ACTUAL LOGIN NAME
define('DB_PASSWORD', 'pass'); // USE YOUR ACTUAL PASSWORD
define('DB_HOST', 'localhost'); // USE YOUR SERVER ADDRESS
define('DB_NAME', 'mydatabase'); // VERIFY THIS IS YOUR DATABASE NAME
if (!$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) {
die('<h1>Could not establish a connection to the database server ' . DB_HOST . ': ' . mysql_error() . '</h1>');
} else {
echo '<h1>We are connected!</h1>';
}
if (!mysql_select_db(DB_NAME)) {
die('<h1>Could not select database ' . DB_NAME . ': ' . mysql_error() . '</h1>');
} else {
echo '<h1>We are in!</h1>';
}
?>
Posted: Mon Jul 31, 2006 9:52 am
by mohson
I see where your coming from but I want to adpapt this:
Code: Select all
<?php
/*Connecting, selecting database*/
$link = mysql_connect("*****", "*****", "*****")
or die("Could not connect : " . mysql_error());
} else {
echo '<h1>We are connected!</h1>';
mysql_select_db("contact_management_system",$link) or die("Could not select database");
?>
Everah | Please do not post your actual login credentials in the forums. That is just down right dangerous (to you mostly).
Posted: Mon Jul 31, 2006 9:56 am
by RobertGonzalez
Code: Select all
<?php
/* Connecting, selecting database*/
$link = mysql_connect("*****", "*****", "*****") or die("Could not connect : " . mysql_error());
if ($link) echo '<h1>We are connected!</h1>';
mysql_select_db("contact_management_system", $link) or die("Could not select database");
// This echo works because if the db selection porked, the die would have been called
echo '<h1>And the DB is good too...</h1>';
?>