简体   繁体   English

使用Oracle数据库进行PDO简单选择查询

[英]PDO simple select query using oracle database

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. 这是一些我在php文件上完成的编码,并试图执行它。

$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 . 我收到的唯一消息是“ 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM