leranjun Posted June 4, 2019 Posted June 4, 2019 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!
Krydos Posted June 4, 2019 Posted June 4, 2019 Did you give $dbUsername select access on the database $dbName?
leranjun Posted June 4, 2019 Author Posted June 4, 2019 Did you give $dbUsername select access on the database $dbName? Yes, the user has access to all the commands.Thank you!
Krydos Posted June 4, 2019 Posted June 4, 2019 Are you saying "Thank you!" that solved the issue or "Thank you!" for trying to help, but it's still not working?
leranjun Posted June 4, 2019 Author Posted June 4, 2019 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 Anyway, I don't think that is the problem. Is there any chance that there are other parts that might have gone wrong?
Krydos Posted June 4, 2019 Posted June 4, 2019 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?
leranjun Posted June 5, 2019 Author Posted June 5, 2019 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.
leranjun Posted June 8, 2019 Author Posted June 8, 2019 I have the least idea why, but it seems to be working now.Thanks for the help anyway!
Recommended Posts