Mysql query in Layar php

Hi

Anyone here familiar with Layar development? - if not this is more of a mysql in php question anyway.

I’m working through the tutorial, Layer with 1d icons, 2d images and 3d objects (http://www.layar.com/documentation/browser/tutorials-tools/layer-1d-icons-2d-images-and-3d-objects/) and attempting to port it to xml. It’s going fine but I’m a little stuck on what the following is actually doing inside the getTransform:

// Binds the named parameter marker ":transformID" to the specified parameter

// value $transformID                
$sql_transform->bindParam(':transformID', $transformID, PDO::PARAM_INT);

// Use PDO::execute() to execute the prepared statement $sql_transform.
$sql_transform->execute();

// Fetch the poi transform.
$rawTransform = $sql_transform->fetch(PDO::FETCH_ASSOC);

Is this a merged mysql query (i.e. results from two table merged if they match ids)? I understand that the first mysql query in getTransform:

$sql_transform = $db->prepare("
      SELECT rel,
             angle,
             rotate_x,
             rotate_y,
             rotate_z,
             translate_x,
             translate_y,
             translate_z,
             scale
        FROM Transform
       WHERE id = :transformID
       LIMIT 0,1 ");

pulls out rel, angle, rotate_x, rotate_y, rotate_z, translate_x, translate_y, translate_z and scale but what does the query array look like when the $sql_transform->bindParam bit is executed? If anyone has a working Layar a print_r of this posted a response would be great to help me visualise this.

Thanks in advance

Garrett

bindParam is just a wrapper for the PDO extension’s bindParam() method in PHP. It’s essentially just a standard prepared statement. They’re most often used to prevent SQL injection attacks by first sending the SQL statement to the SQL server, then “binding” the variables to their placeholders in the SQL statement.

So basically, it tells the SQL server that it’s about to execute the following SQL:


$sql_transform = $db->prepare("
      SELECT rel,
             angle,
             rotate_x,
             rotate_y,
             rotate_z,
             translate_x,
             translate_y,
             translate_z,
             scale
        FROM Transform
       WHERE id = :transformID
       LIMIT 0,1 ");

Then it tells the server (VIA the bindParam method) that before it executes that SQL it should replace the string :transformID with the value of $transformID, and that it will be of type integer:


$sql_transform->bindParam(':transformID', $transformID, PDO::PARAM_INT);

After it sends the execute() method, it fetches the results VIA $rawTransform = $sql_transform->fetch(PDO::FETCH_ASSOC);
I’m not sure if that will fetch one row, or all rows … you’ll have to check the Layar documentation on that as I’m not familiar with it. Either way though, $rawTransform should be an associative array. You can check the structure of it by calling print_r($rawTransform);

Hope that answers your question some.

Brillant, yes it does answer it. So in mapping it accross to xml I can just forget it, all I need is the equivalent of the mysql query parsed out of my loaded simplexml.

Never seen PDO before, just been reading about it, it has been about two years since I’ve done any php. Thanks for your very clear explanation.

Garrett

No problem. Glad I could help.