2

I try to get some values from db

$client_ids = array('client_id' => $this->arParams['client_id']);
 print_r($client_ids);
 $client_ids_in = implode(',', array_fill(0, count($client_ids), '?'));
 $query = "SELECT odc.curr_id FROM office.dictionary_currency AS odc LEFT JOIN office.adwords_clients_google AS oacg ON odc.curr_code = oacg.client_currency WHERE oacg.client_id IN ($client_ids_in)";
        $google_currency = $this->DB->prepare($query);
        $google_currency->execute($client_ids);
        $google_currency->setFetchMode(PDO::FETCH_ASSOC);
        $google_currency = $google_currency->fetch();
        $google_currency = $google_currency['curr_id'];

$client_idslooks like

Array
(
    [client_id] => 15087
)

$query

SELECT odc.curr_id FROM office.dictionary_currency AS odc LEFT JOIN office.adwords_clients_google AS oacg ON odc.curr_code = oacg.client_currency WHERE oacg.client_id IN (?)

and I get an error

PHP Warning:  PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /var/www/instruments/reports/report.php on line 531

it means,error in row

$google_currency = $this->DB->prepare($query);

What's wrong?How to fix it?

Heidel
  • 3,174
  • 16
  • 52
  • 84

2 Answers2

1

Change your code

 $client_ids = array('client_id' => $this->arParams['client_id']);

into something like

 $client_ids = array($this->arParams['client_id']);

So $client_ids is like

Array
(
   0 => 15087
)
Zamrony P. Juhara
  • 5,222
  • 2
  • 24
  • 40
1

If you use generic placeholders ? you need to pass to execute a non-associative array. So you can either remove 'client_id' key form your array, or use a named placeholder.

Possible solution

$client_ids = array($this->arParams['client_id']);
Reversal
  • 622
  • 5
  • 19