简体   繁体   English

PHP PDO Oracle字符类型绑定错误

[英]PHP PDO Oracle character type binding error

I have a table in oracle (11g xe) 'bill' which has a structure like below: 我在oracle(11g xe)'bill'中有一个表,其结构如下:

key_id number(10),
bill_no number(10),
bill_date date,
cons_id_no varchar(10),
cons_no char(15)

I am connecting to the database using PHP::PDO like below: 我正在使用PHP :: PDO连接到数据库,如下所示:

public function findByConsumerNumber($consumerNumber) {
   $pdo = new \PDO('oci:dbname=/localhost:1521/xe','kaushik','123');
   $stmt = $pdo->prepare('SELECT * FROM bill WHERE cons_no = :cons_no');
   $stmt->bindParam(':cons_no',$consumerNumber);
   $stmt->execute();
   return $this->findCollection($stmt->fetchAll());
}

But on executing I am getting 0 results. 但是执行时我得到0个结果。 But when I change the code as follows, I am getting results: 但是当我如下更改代码时,我得到的结果是:

public function findByConsumerNumber($consumerNumber) {
   $pdo = new \PDO('oci:dbname=/localhost:1521/xe','kaushik','123');
   $stmt = $pdo->prepare("SELECT * FROM bill WHERE cons_no = '" . $consumerNumber . "'");
   $stmt->execute();
   return $this->findCollection($stmt->fetchAll());
}

I am not able to find the actual problem. 我找不到实际的问题。

Note: when I try to find results based on cons_id_no as in the first method given above, I am getting results. 注意:当我尝试像上面第一个方法一样基于cons_id_no查找结果时,我正在获取结果。

You have a spelling mistake : consumberNumber should be consumerNumber 您有一个拼写错误:consumberNumber应该是ConsumerNumber

You should look into Dependency injection, initializing a db connection every time a method is called is crazy. 您应该研究依赖注入,每次调用一个方法都是疯狂的,因此初始化数据库连接。

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

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