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 https://forums.phpfreaks.com/topic/296033-pdo-connection-status-turned-into-a-variable-to-echo-elsewhere/ 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 https://forums.phpfreaks.com/topic/296033-pdo-connection-status-turned-into-a-variable-to-echo-elsewhere/#findComment-1510602 Share on other sites More sharing options...
cloudll Posted May 2, 2015 Author Share Posted May 2, 2015 awesome, thanks Quote Link to comment https://forums.phpfreaks.com/topic/296033-pdo-connection-status-turned-into-a-variable-to-echo-elsewhere/#findComment-1510603 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.