MiloG21 Posted September 13 Share Posted September 13 Hi there, I am just a beginner in coding, and recently just followed a tutorial (https://www.youtube.com/watch?v=3p_-jPWne4Y&ab_channel=QuickProgramming) to incorporate PHP to my website for a forum page. I have already exported the database and uploaded my website into my website domain (z.com), but for some reason the website displays "Could not connect to database". I have already created the connection.php file that I also followed from another video as seen below: <?php $con=mysqli_connect('localhost:3306','cupnvhkz_user','Password','cupnvhkz_deed-ph'); if(!$con) { die(' Please Check Your Connection' .mysqli_error($con)); } ?> I have also added this to my index.php: <?php include "connection.php"; Is there anything else that I am missing? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 13 Share Posted September 13 The message is "Could not connect to database" but I don't see that in the code you posted... So where is it coming from? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 13 Share Posted September 13 your own connection.php code may be running w/o error. the tutorial script has its own connection code in config.inc.php. this is where the message you are getting is coming from. downloading and running code you find on the web, without reading it to learn what it is doing, doesn't teach you anything. as to the connection code you found and posted here. mysqli_error($con) requires a valid connection, when using mysqli procedural statements. therefore, this code won't report the actual reason for the connection failure and will produce its own error at the mysqli_error($con) statement. as to both the connection code you found and what is included in this out of date tutorial, modern php (8+) uses exceptions for errors and any discrete error handling logic will never get executed upon an error and should be removed, simplifying the code. i recommend that you update to use php8+ and find a recent tutorial. 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.