EDIT

Thanks JayPan;

But unfortunately that query (your answer below) did not work and instead sent the module into an immediate error of the same nature - and this time the module would not respond at all - it would previously process credit cards for products that were non-recurring - I stand corrected by me, myself and I - as it only fails in TEST mode - and works in LIVE mode all the way, but STILL does the same otherwise and would not "error out" until the process payment stage ONLY on recurring products - and now it it goes into immediate error upon attempting to add a product to the cart or EITHER kind. Clearing the caches had no effect

I had to put a previous crippled module back on the site so it will at least process regular products with charge cards until i can go through each change in each query and code sub-routine to find the one causing this.

It must be other code that works between the card gateway to the customer management API calls there and the API plan management and use features in the module.

ORIGINAL POST

How do i change this into Drupal 7 syntax? It has both a token placeholder for text and uses a magic get function in it. it wprked in Drupal 6

"SELECT rfid FROM {the_table} WHERE customer_id = '%s'", $customer->__get('id')));

I tried

'SELECT rfid FROM {the_table} WHERE customer_id = %s', array('%s' => $customer->__get('id')));

BUT it appears to throw

Recoverable fatal error: Object of class DatabaseStatementBase could not be converted to string in DatabaseStatementBase->execute() (line 2171 of /. . . /database.inc).

Query Coder turned it into this:

$query = db_select('{the_table}', '');
$query->fields('rfid', array(''));
$query->condition('customer_id', '%s');
$result = $query->execute();

which I tried as

$query = db_select('the_table', 'the_table');
$query->fields('the_table', array('rfid'));
$query->condition('the_table.customer_id', '%s');
$query->execute();
$result = $query

It is a Drupal 6 code conversion to Drupal 7 and the magic get is coming from a session and generated by another web server and then used to set a unique local customer id

Does someone know how to convert this kind of query so it won't throw the error ??

Comments

Jaypan’s picture

Coding questions belong in the Module Development and Code Questions section of the forum. You can move the thread by editing the original post and choosing that forum as the forum.

To answer your question you can do this:

db_query("SELECT rfid FROM {the_table} WHERE customer_id = :id", array(':id' => $customer->__get('id')));

Or this:

$query = db_select('the_table', 'the_table')
->fields('the_table', array('rfid'))
->condition('customer_id', $customer->__get('id'));