kaushik
kaushik

Reputation: 2492

PHP PDO Oracle character type binding error

I have a table in oracle (11g xe) 'bill' which has a structure like below:

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:

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. 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.

Upvotes: 1

Views: 238

Answers (1)

hendr1x
hendr1x

Reputation: 1501

You have a spelling mistake : consumberNumber should be consumerNumber

You should look into Dependency injection, initializing a db connection every time a method is called is crazy.

Upvotes: 1

Related Questions