moltra Posted March 18, 2012 Share Posted March 18, 2012 I am trying to create a web service using restful service tonic frame work to pull data from my website www.serviidb.com and I can print_r the output to firefox poster. I am using SQL queries to pull the data form a mysql database. I would like to be able to select the query for the data I want at the beginning of the code and select the output format at the end. I am looking at having sections of the code to get "plugins", "video", "audio", and "user". I am thinking about use select case to determine the mysql query to run. I have programming exp in VB, basic and fortran. Here is the URL I am using for the get command. http://serviidb.com/api/plugins here is the code I am using right now. <?php class TaskDataManager { public static function get($taskId, $input){ echo $taskid . "\n"; //Connect To Database $hostname='hostname'; $username='username'; $password='password'; $dbname='dbname'; mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); //echo 'taskid: ' . $taskId . "\n"; if($taskId=="plugins"){ //echo $input . "\n"; $plgnsql='SELECT taxonomy_term_data.name, field_revision_field_revision.field_revision_value as version, file_managed.uri as URL' . ' FROM taxonomy_term_data ' . ' left join field_data_field_plugins on taxonomy_term_data.tid = field_data_field_plugins.field_plugins_tid ' . ' left join field_revision_field_revision on field_revision_field_revision.revision_id = field_data_field_plugins.revision_id ' . ' left join file_usage on field_data_field_plugins.entity_id = file_usage.id' . ' left join file_managed on file_usage.fid = file_managed.fid' . ' WHERE (field_data_field_plugins.bundle ="plugin")' . ' '; //$format='json' $result = mysql_query($plgnsql); //$mark =jsob_encode("plugins"); $plugins = array(); //echo $result . "\n"; //$response->addHeader('Content-type', 'application/json'); while($response = mysql_fetch_array($result, MYSQL_ASSOC)){ $response[url] = substr_replace($response[url],'http://serviidb.com/sites/default/files/',0,9); $reponse = json_encode($response); print_r ($reponse) . "\n"; } //print_r ($response) . "\n"; return true; } if($taskId=="video"){ echo $input . "\n"; //echo "started feed code" . "\n"; return true; } } } ?> Here is the output I am getting. I am trying to figure out how to get the json output to look like the second code below. {"name":"Blip TV","version":"0","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/BlipTVUrlExtractor.groovy"}{"name":"CBS","version":"0","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/CBS.groovy"}{"name":"iPlayer (UK)","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/IPlayer.groovy"}{"name":"4oD (UK)","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/Channel4od.groovy"}{"name":"YouTube","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/youtube.groovy"}{"name":"LiveFeeds","version":"3","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/livefeeds.groovy"}{"name":"GameSpot","version":"1","URL":"http:\/\/serviidb.com\/sites\/default\/files\/createplugin\/gamespot.groovy"} Want. {"plugins":[{"name":"Blip TV", "version":0, "url":"http:\\serviidb.com/sites/default/files/Create Plugin/BlipTVUrlExtractor.groovy"},{"name":"CBS", ....}]} I am also trying to figure out how to get the output in the xml format also. Thanks is advance for the help. Quote Link to comment https://forums.phpfreaks.com/topic/259189-restful-service-using-tonic-framework/ Share on other sites More sharing options...
moltra Posted March 19, 2012 Author Share Posted March 19, 2012 I can get a basic json format returned by using print_r, but I cannot figure out how to get the proper response for a REST service. I am also trying to get the xml and html formats setup. I have all the mysql queries figured out and just need the help to convert the data from the mysql query into the json, xml and html formats. Please see prior post in this thread for the code I have set up so far. I appreciate any and all help. I hope that I read the rules of this board on replies to your own posts. Quote Link to comment https://forums.phpfreaks.com/topic/259189-restful-service-using-tonic-framework/#findComment-1329025 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.