Jump to content

PHP, MySQL | Z.com domain link leads to "Could not connect to database" screen


Recommended Posts

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?

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.