Jump to content

Recommended Posts

Posted

Hi,

I have been trying to connect to my MySQL database added through cPanel with PHP.

It turned out that the connection was successful, but it cannot execute any commands.

I tried to execute the command in my local IDE (I am using PhpStorm), and it succeeded. I used the same configuration with mysqli, but it doesn't work.

 

In connect.php:

<?php
    $dbServername = "ricky.heliohost.org:3306";
    $dbUsername = "username";
    $dbPassword = "password";
    $dbName = "test";
    $conn = new mysqli($dbServername, $dbUsername, $dbPassword, $dbName);
    if ($conn->connect_error) {
        die("Connection Error: " . $conn->connect_error);
    }
    echo "Connection successful";
    $stmt = $conn->prepare("SELECT * FROM test");
    $stmt->execute(); 

The output is just "Connection successful"; it does not execute the SELECT statement.

Can anyone please help me?

Thank you very much!

Posted

Did you give $dbUsername select access on the database $dbName?

 

Yes, the user has access to all the commands.

Thank you!

Posted

Are you saying "Thank you!" that solved the issue or "Thank you!" for trying to help, but it's still not working?

Posted

Are you saying "Thank you!" that solved the issue or "Thank you!" for trying to help, but it's still not working?

Aha, sorry for the confusion. I'm just saying thank you for politeness  :D

Anyway, I don't think that is the problem. Is there any chance that there are other parts that might have gone wrong?

Posted

Since your code sample has all of the useful information edited out I looked around on your account. I don't even see a select statement in the beta directory. Are you selecting from the table test like you posted or tea which actually exists?

Posted

Since your code sample has all of the useful information edited out I looked around on your account. I don't even see a select statement in the beta directory. Are you selecting from the table test like you posted or tea which actually exists?

Well I'm just using test for security purposes. The actual database is tea.

Guest
This topic is now closed to further replies.
×
×
  • Create New...