Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (4k points)

When I try and run my query it turns out blank (not NULL, just not printing a value). If I run my query in my database it returns the value Im looking for.

When I run my code it notifies me the connection was successful. (I didnt include my db variable info to protect the sensitive info but it is correct)

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    echo "error";
} 
else{
    echo "conn successful";
}


$sql = "SELECT app_ref_person_submitted_by
            FROM vacancy_applications
            WHERE app_ref_vacancy = 306";


$result = $conn->query($sql);
echo $result;

$conn-> close();

1 Answer

0 votes
by (8.7k points)

 Check out the below code to  help  out to run a Sql  query in PHP:

<?php

$conn = new mysqli('localhost', 'demo_try', 'demo_try', 'demo_try');

 

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

    echo "encountered error";

else{

    echo " connection successful";

}

$sql = "SELECT app_ref_person_submitted_by

        FROM vacancy_applications

        WHERE app_ref_vacancy = 306";

 

$result = $conn->query($sql);

 

while($row = $result->fetch_array()){

    echo $row['app_ref_person_submitted_by'];

}

 

$conn-> close();

?>

Browse Categories

...