SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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/b...nd-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:

    Code:
    // 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:

    Code:
    $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

  2. #2
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    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:
    Code:
    $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:

    PHP Code:
    $sql_transform->bindParam(':transformID'$transformIDPDO::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.

  3. #3
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    No problem. Glad I could help.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •