sprint database query

Permalink
How can I setup a database query using sprintf

I have tried
$db = Loader::db();
$query = $db->Execute(sprintf("select....")

but cant seem to et it to work correctly.
has anyone got any ideas?

Thanks

edbeeny
 
ScottC replied on at Permalink Reply
ScottC
eh well,

if you search for $result = $db->query('select * from Blocks where bID = ?',array($bID));

this kind of takes the place of sprintf and escapes where needed etc.

if you can provide a valid string in your query/execute function arg it doesn't matter where that comes from, but i'd personally stick to the "core" method w/ adodb.

If you decide you need to port your package to another framework it isn't that big a deal.
edbeeny replied on at Permalink Reply
edbeeny
Scott,

Thank you for your reply.
I think my main problem is what Im trying to do.
I have a php file which generates an xml file from a db. this xml file is then used ion a query else where.

I think the issue is the file is not loading c5 as it is stand alone.
What I need to so is to get a php file to load c5 or have another way to connect to the database.
I have tried to include the file but keep getting this error
Class 'Loader' not found in...
Thanks for your help
edbeeny replied on at Permalink Reply
edbeeny
Ok My first issue
This is the code provided by google I have made a slight amendment to the SearchUrl path.
function searchLocationsNear(center) {
     var radius = document.getElementById('radiusSelect').value;
    var searchUrl = <?$this->getBlockPath()?>"/generate-store-xml.php?lat=" + center.lat() + "&lng=" + center.lng() + "&radius=" + radius;
     GDownloadUrl(searchUrl, function(data) {
       var xml = GXml.parse(data);
       var markers = xml.documentElement.getElementsByTagName('marker');
       map.clearOverlays();
       var sidebar = document.getElementById('map_sidebar');
       sidebar.innerHTML = '';
       if (markers.length == 0) {
         sidebar.innerHTML = 'No results found.';
         map.setCenter(new GLatLng(40, -100), 4);
         return;
       }


This isn't calling the php file which generates the xml file.
Have you any suggestions?
Thanks
ScottC replied on at Permalink Best Answer Reply
ScottC
move your searchUrl to $this->getBlockTypeToolsUrl() or something along those lines(check out the page_list block and rss.php under tools) and then place that generate-store-xml file in there, there being blocks/search_locations/tools/generate-store.xml.php

You might have to futz around a bit to get the path exactly right but it does in fact work.

If you foresee using this across multiple blocks or a single_page or something then i'd just place it in a package and do getToolsUrl('filename','packageName');

Hope that helps

Basically it just routes the base environment through that tools url so Loader and anything loaded via the dispatcher are available down the chain.

-Scott
edbeeny replied on at Permalink Reply
edbeeny
Scott,
You are a star.
I have managed to get this all working well now.
Thanks for all your help
Ed