Cloud 9 IDE can't connect to database

前端 未结 1 1983
予麋鹿
予麋鹿 2020-12-22 02:01

I have tried a number of things to connect to my database in cloud 9 but I keep getting similar errors.

This is my PHP code:



        
相关标签:
1条回答
  • 2020-12-22 02:56

    Credit to Loz Cherone

    When using Cloud 9 IDE, the php variables $ID and $C9_USER mentioned in this article are not defined.

    In order to retrieve these variables for use in your code, you must use the cloud 9 ide terminal by pressing ALT + T and entering:
    echo $ID
    echo $C9_USER

    Then take those values and place them in a variable in your php code like so:

    <?php
        // Create connection
        $IP = "value from terminal";
        $C9_USER = "value from terminal";
        $con=mysqli_connect($IP, $C9_USER, "", "c9");
    
        //mysqli_connect(host,username,password,dbname); << guideline
    
        // Check connection
        if (mysqli_connect_errno()) {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
    ?>
    

    SIDE NOTE: Make sure when running the mysql code that you have the data base turned on. You can turn it on by typing mysql-ctl start in the terminal.

    0 讨论(0)
提交回复
热议问题