cloudll Posted May 2, 2015 Share Posted May 2, 2015 Hey guys, I am currently using the following code to connect to my database and to display custom messages for if it has connected to the database or not. I would quite like to display these messages in my footer. I was wondering if its possible to turn the messages into a variable to echo them in the footer? Thanks for any tips. $hostname = 'localhost'; $database = 'engine'; $username = 'root'; $password = ''; try { $dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password); echo 'Connected to database'; } catch(PDOException $e) { echo 'error connecting to database.'; } error_reporting(0); Quote Link to comment Share on other sites More sharing options...
venkatpvc Posted May 2, 2015 Share Posted May 2, 2015 you could try like below; if (!$dbh) { $errormsg = "Failed to connect"; } else { $errormsg = "Connected to DataBase"; } Quote Link to comment Share on other sites More sharing options...
cloudll Posted May 2, 2015 Author Share Posted May 2, 2015 awesome, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.