Jump to content

[Solved] Not able to execute SQL commands


leranjun

Recommended Posts

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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