i want to try to run simple select query to know if the database connection is working fully.
Here is some coding i have done on php file and tried to execute it.
$tns = "
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = COD3R-PC)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = XE)
)
)
";
try {
$conn = new PDO("oci:dbname=".$tns, '****', '****');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo 'Connected to database';
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
/*if($_POST['searchFilter']){
$searchFilter = $_POST['searchFilter'];
$stmt = $conn->prepare("SELECT ROOM, GUEST_NAME FROM RESERVATION_GENERAL_2 WHERE ROOM LIKE ? OR GUEST_NAME LIKE ?");
$stmt->execute(array('%'.$searchFilter.'%','%'.$searchFilter.'%' ));
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (empty($results)){
print_r(json_encode(0));
}
else{
print_r(json_encode($results));
}
}*/
$stmt = $conn->prepare("SELECT * FROM RESERVATION_GENERAL_2");
$stmt->execute(array($stmt));
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
The only message i got is Connected to database
.
I am not sure if it is really connected to database or not, cuz i dont know about try and catch much.
and after that there is a blank page no result.
Please see the screenshot for the table name and columns.
what am i doing wrong please tell.
Change this line:
$stmt->execute(array($stmt));
To:
$stmt->execute();
You don't have any parameters to execute, in the scenario below it would work:
$stmt = $conn->prepare("SELECT * FROM RESERVATION_GENERAL_2 WHERE reservation_id = ?");
$stmt->execute(array($id));