Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

SS mySQL query halp


3 Posts   1419 Views


Community Member, 25 Posts

6 October 2010 at 10:13am

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;   


Forum Moderator, 1805 Posts

6 October 2010 at 11:26am

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)


Community Member, 162 Posts

6 October 2010 at 3:02pm

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();