Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SS mySQL query halp

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1370 Views
  • slavelabourer
    Community Member
    25 Posts

    SS mySQL query halp Link to this post

    So i'm a bit of a newbie having trouble with this sql query. I have a form in the cms that allows a user to input a vimeo video ID and then pass that to the vimeo moogaloop api.

    So i've written a query the writes some xml to the head of the current videopage

    $query = (int)DB::query("SELECT VimeoID FROM `VideoPage`WHERE `ID` = '$this->ID'")->value();

    for some reason it keeps returning the value as 0. Any thoughts are appreciated.

             $result = mysql_query($query);
             $doc = new DomDocument('1.0');

          // create root node
             $root = $doc->createElement('vimeoURL');
             $root = $doc->appendChild($root);
              // add node for each row
              $occ = $doc->createElement('vimeoURL');
              $occ = $root->appendChild($occ);
              $child = $doc->createElement('URL');
              $child = $occ->appendChild($child);
              $value = $doc->createTextNode('URL' + $result);
              $value = $child->appendChild($value);
          $xml_string = $doc->saveXML();
          //header('Content-Type: application/xml; charset=ISO-8859-1');
          echo $xml_string;   

  • swaiba
    Forum Moderator
    1792 Posts

    Re: SS mySQL query halp Link to this post

    hi dan, is there a reason not to use DataObject::get_by_id?

    $doVideoPage = DataObject::get_by_id('VideoPage',$this->ID);
    $occ = $doc->createElement($doVideoPage->vimeoURL); //assuming vimeoURL is in $db of $doVideoPage)

  • _Vince
    Community Member
    161 Posts

    Re: SS mySQL query halp Link to this post

    If you really want to use SQLQuery, I think it would look more like this

    $query = new SQLQuery();
    $query->select = array("VimeoID");
    $query->from = array("VideoPage");
    $query->where = array("ID = $this->ID");

    $result = $query->execute()->value();

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.