mysql_escapef

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 19, 2012   (RSS)

By Toledoh - June 19, 2012

Hi Guys,

This seems to me like it should work... but it doesn't.

Please look at;http://www.fibreking.com/products_a.php?num=4 and http://www.fibreking.com/products_b.php?num=4

In products_a I have the following code;
<?php

// load record from 'items'
list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'where' => whereRecordNumberInUrl(0),
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$itemsRecord = @$itemsRecords[0]; // get first record

echo '<h3>where clause</h3>';
showme(mysql_escapef('products = ?', $itemsRecord['num']));

list($downloadsRecords, ) = getRecords(array(
'tableName' => 'downloads',
'where' => mysql_escapef('products = ?', $itemsRecord['num']),
'allowSearch' => false,
'debugSql' => true,
));
$downloadsRecord = @$downloadsRecords[0]; // get first record

?>


and in products_b;
<?php

// load record from 'items'
list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'where' => whereRecordNumberInUrl(0),
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$itemsRecord = @$itemsRecords[0]; // get first record

echo '<h3>where clause</h3>';
showme(mysql_escapef('products = ?', $itemsRecord['num']));

list($downloadsRecords, ) = getRecords(array(
'tableName' => 'downloads',
'where' => 'products = 4',
'allowSearch' => false,
'debugSql' => true,
));
$downloadsRecord = @$downloadsRecords[0]; // get first record

?>


By looking at the de-bug stuff, I think that the where search is pretty much the same. ie. Show me all downloads where products=4.... when I hard code it - it works (products_b) but not when I use the mysql_escapef...

Can you help? I've attached the complete files if it helps.
Cheers,

Tim (toledoh.com.au)
Attachments:

products_a.php 5K

products_b.php 5K

Re: [Toledoh] mysql_escapef

By Jason - June 19, 2012

Hi Tim,

I took a look. The only difference between the two is that products_a uses the where clause:

products = '4'

and products_b uses

products = 4

If you hard coded in the single quotes into products_b, would you get the same result? Another thing you could try would be:


'where' => "products =".intval($itemsRecord['num']),

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/