1

I am trying to do a SQL query with ADODB, which is used in the OXID framework.

$database = oxDb::getDb();
$sql = 'SELECT oxobjectid FROM oxobject2discount WHERE oxdiscountid = '.$oxdiscountid;
$resultado = $database->execute($sql);

This will always throw and exception error. I know you can use the function Prepare with ADODB to sanitize the statement and get ready to use it. However I am unable to call it in Oxid, it seems.

Anyone knows what to do?

prgrm
  • 3,734
  • 14
  • 40
  • 80
  • what is value of `$oxdiscountid` ? – Niklesh Raut Jun 01 '16 at 11:14
  • A bunch of characters taken from a database (char32). I will try forcing $sql into a string. – prgrm Jun 01 '16 at 11:18
  • This worked. You should delete the semicolon after $oxdiscountid but that is obviously a typo. Also post it as an answer so I can check it as answered. – prgrm Jun 01 '16 at 11:38
  • 1
    Just wanted to mention that you could also use the OXID Framework. Just instantiate `oxbase`, call `init` with the table name. Then you can build a select string with `buildSelectString` and assign the record with `assignRecord`. – Alex2php Jun 01 '16 at 15:00

1 Answers1

2

Use " quotes

$sql = 'SELECT oxobjectid FROM oxobject2discount WHERE oxdiscountid = "'.$oxdiscountid;.'"';
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109