How do I run an sql query in php

0 votes

When I attempt to run my query, nothing happens (not NULL, just not printing a value). When I run my query against my database, the desired result is returned.

I am informed that the connection was successful when I execute my code. (I omitted my database variable information to safeguard the sensitive information, but it is accurate.)

$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();

Can someone please help me with this?

Sep 8, 2022 in Database by Kithuzzz
• 38,010 points
637 views

1 answer to this question.

0 votes

Try this:

<?php
$conn = new mysqli('localhost', 'jaydeep_mor', 'jaydeep_mor', 'jaydeep_mor');

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);

while($row = $result->fetch_array()){
    echo $row['app_ref_person_submitted_by'];
}

$conn-> close();
?>

I hope this helps you.

answered Sep 10, 2022 by narikkadan
• 63,720 points

Related Questions In Database

0 votes
1 answer

How do I perform an IF THEN statement in an SQL SELECT?

The CASE statement is the closest to IF in ...READ MORE

answered Feb 16, 2022 in Database by Vaani
• 7,060 points
1,415 views
0 votes
0 answers

How do I query for all dates greater than a certain date in SQL Server?

I tried this: SELECT * FROM dbo.March2010 A WHERE ...READ MORE

Aug 29, 2022 in Database by Kithuzzz
• 38,010 points
636 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,060 points
675 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4, 2022 in Database by Vaani
• 7,060 points
372 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
10,049 views
0 votes
1 answer

Why is not preferable to use mysql_* functions in PHP?

The reasons are as follows: The MySQL extension: Does ...READ MORE

answered Sep 7, 2018 in Database by DataKing99
• 8,240 points
1,070 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How do I obtain a Query Execution Plan in SQL Server?

There are several ways to get an ...READ MORE

answered Sep 20, 2022 in Database by narikkadan
• 63,720 points
1,023 views
0 votes
1 answer

How do I limit the number of rows returned by an Oracle query after ordering?

Use a subquery for this like: select * from ...READ MORE

answered Sep 15, 2022 in Database by narikkadan
• 63,720 points
1,885 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP