This is a discussion on mySQL Results To XML within the PHP General forums, part of the PHP Programming Forums category; Hi, Here's the mission, creating a movie DB, I need the results returned from mySQL in an XML format ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
Here's the mission, creating a movie DB, I need the results returned from mySQL in an XML format for use with the FLASH Professional DataGrid. Any tips on formating mySQL results would be grand. Here's the structure of the DB, if needed. DVD Table *Title ID *Title *Genre *Actor *Director *Producer *Date Purchased *Price *Date Released *Length *Plot *Review(*****) *Rating person table *Producer ID *First Name *Last Name *Director ID *First Name *Last Name Actors_Link actor_link_id just a primary auto-increment number person_id movie_id role_id |
|
|||
|
On 10/6/07, CK <jobs@bushidodeep.com> wrote:
> Hi, > > > Here's the mission, creating a movie DB, I need the results returned > from mySQL in an XML format for use with the FLASH Professional > DataGrid. Any tips on formating mySQL results would be grand. Here's > the structure of the DB, if needed. you could easily just print the xml manually. <dvd> <titleID>foo</titleID> <bar>etc</bar> </dvd> or, i believe mysql will return XML output but i'm not sure a PHP function exists to do that. no need to use fancy DOM functions, outputting XML is easy, parsing it is when you need to use the special functions and such. |
|
|||
|
> -----Original Message----- > you could easily just print the xml manually. > > <dvd> > <titleID>foo</titleID> > <bar>etc</bar> > </dvd> > > or, i believe mysql will return XML output but i'm not sure a PHP > function exists to do that. > > no need to use fancy DOM functions, outputting XML is easy, parsing it > is when you need to use the special functions and such. Here's the 'functions_xml.inc.php' file I use, it has served me well and handles I believe all tag cases, personally I'm a big fan of using the attributes as they're most easily parsed out in the PHP DOM functions: --------------------------------8<-------------------------------------- --- <?php /** * Aborts XML output with an Error message * * @return string xml formatted tags and data * @param string $message the error message to output * @version 1.3 * @date 07/14/05 */ function XML_exit($message) { header( "Content-type: text/xml" ); print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; //TODO: [dv] we should probably put an error code so that it's easier for the scripts to parse //print xmltag('error', array('code'=>'TBD', 'string'=>$message)); print xmltag('error',null, 1); print xmltag('code','TBD'); print xmltag('string',$message); print xmltag('error',null, 2); exit; } /** * Returns a well formed lowercase XML tag string suitable for printing to screen * * tagType=1: is like tagType=3, but without the /> * tagType=2: is the closing </xmltag> only. * * tagType=3: * <xmltag foo=bar /> * * also note that array('foo'=>'bar','__VALUE'='1234') will generate: * <xmltag foo=bar>1234</xmltag> * * tagType=4: * <xmltag> * <foo>bar</foo> * </xmltag> * * @return string xml formatted tags and data * @param string $xmltag is the tag name to surround * @param mixed $data data to output between the tags, if $data is an array, it will be expanded as KEY=VALUE in the tag. If there is an array element __VALUE that will be a value between XML tags after the list of attributes * @param int $tagType 1=start tag only, 2=end tag only, 3=default, 4=verbose tag * @todo use recursion to get nested arrays working, especially for tagType=4 * @version 1.6 * @date 01/16/06 */ function xmltag($xmltag, $data, $tagType = 3) { // convert spaces to underscores and makes it lowercase as per XML specification $xmltag = strtolower(str_replace(' ','_', $xmltag )); // encode all characters that need to be converted for export into XML $data = xmlentities($data); //we put this first, as it is used most frequently if ($tagType == 3) { if (isset($data)) { if (is_array($data)) { if (isset($data['__VALUE'])) { $value_data = $data['__VALUE']; unset($data['__VALUE']); } $tmp = '<'.$xmltag; foreach($data as $key => $value) { if ( is_bool($value) ) $value = ($value === true)?'true':'false'; $tmp .= ' '.$key.'="'.$value.'"'; } if (isset($value_data)) { if ( is_bool($value_data) ) $value_data = ($value_data === true)?'true':'false'; $tmp .= ">".$value_data."</".$xmltag.">\r\n"; } else $tmp .= " />\r\n"; return $tmp; } else { if ( is_bool($data) ) $data = ($data === true)?'true':'false'; return '<'.$xmltag.'>'.$data.'</'.$xmltag.">\r\n"; } } else return '<'.$xmltag." />\r\n"; } //tag type 3 if ($tagType == 1) { $tmp = '<'.$xmltag; if (is_array($data)) { foreach($data as $key => $value) { if ( is_bool($value) ) $value = ($value === true)?'true':'false'; $tmp .= ' '.$key.'="'.$value.'"'; } } $tmp .= ">\r\n"; return $tmp; } //tag type 1 if ($tagType == 2) return '</'.$xmltag.">\r\n"; if ($tagType == 4) { if (isset($data)) { if (is_array($data)) { $tmp = '<'.$xmltag.">\r\n"; foreach($data as $key => $value) { if ( is_bool($value) ) $value = ($value === true)?'true':'false'; $tmp .= '<'.$key.'>'.$value.'<'.$key."/>\r\n"; } $tmp = '</'.$xmltag.">\r\n"; return $tmp; } else { if ( is_bool($data) ) $data = ($data === true)?'true':'false'; return '<'.$xmltag.'>'.$data.'</'.$xmltag.">\r\n"; } } else return '<'.$xmltag." />\r\n"; } //tag type 4 } /** * Print out an array in XML form (useful for debugging) * @access public * @param string $myArray the array to output in XML format * @author Daevid Vincent [daevid@] * @version 1.0 * @date 07/19/05 * @todo It would be nice if we could extract the array's variable name and output that as an attribute */ function print_r_xml($myArray) { print xmltag('ARRAY', null, 1); foreach($myArray as $k => $v) { if (is_array($v)) print_r_xml($v); else print xmltag($k,htmlspecialchars($v)); } print xmltag('ARRAY', null, 2); } ?> |
|
|||
|
On 10/6/07, Daevid Vincent <daevid@daevid.com> wrote:
> Here's the 'functions_xml.inc.php' file I use, it has served me well and > handles I believe all tag cases, personally I'm a big fan of using the > attributes as they're most easily parsed out in the PHP DOM functions: I made this at one point: function array2xml($array, $complete = true) { $xml = "<$array[NODE] "; unset($array['NODE']); ksort($array); foreach(array_keys($array) as $key) { $xml .= "$key=\"$array[$key]\" "; } if($complete) { $xml .= "/"; } $xml .= ">"; return $xml; } it takes an associative array with a key of "NODE" for the node name and makes it a single xml node with all the content in attributes. it even alphabetizes the attributes. special preparing of the data (like htmlspecialchars()) might be needed to ensure XML compliance. i made one to translate it into nodes, but i think at the time i read that attribute parsing is quicker. calling it looks like this: $context['NODE'] = "context-info"; $context['current-datetime'] = format_time_xml(time(),"UTC"); $context['current-hostname'] = $_SERVER['HTTP_HOST']; $context['current-page'] = $_SERVER['PHP_SELF']; $xml = array2xml($context); |
|
|||
|
<posted & mailed>
mike wrote: > I made this at one point: > > function array2xml($array, $complete = true) { > $xml = "<$array[NODE] "; > unset($array['NODE']); > ksort($array); > foreach(array_keys($array) as $key) { > $xml .= "$key=\"$array[$key]\" "; > } > if($complete) { > $xml .= "/"; > } > $xml .= ">"; > return $xml; > } What about the reverse - converting the XML back to MySQL? (I'm interested for an address book project, but don't know too much of XML or mySQL!) |
|
|||
|
Hi fellows:
I'm trying to mount PHP5 ( the last stable version from php.net) under a IIS6 (win2k3 SP2), and when I run the .msi and it finish it said that is not possible the configure httpd.conf, which is a very big mistake 'cause I'm specify that I use IIS6. After that I try making a manual configuration and I recive a CGI error. I need help ASAP. Este correo ha sido enviado desde el Politécnico de Informática "Carlos Marx" de Matanzas. "La gran batalla se librará en el campo de las ideas" |
|
|||
|
Hi Alberto,
Try using the php5isapi.dll instead of CGI. Make sure you have an entry for PHP5 in your Web Service Extensions list, and that it is marked as Allowed. Also, open the properties of your Web Sites folder in IIS Manager, go to the Home Directory Tab, click Configuration, and make sure the php5isapi.dll is mapped to the .php extension. Regards, Carlton Whitehead ----- Original Message ----- From: "Alberto GarcÃ*a Gómez" <alberto@ipimtzcm.rimed.cu> To: php-general@lists.php.net Sent: Monday, October 8, 2007 9:57:42 AM (GMT-0500) America/New_York Subject: [php] PHP5 under IIS6 Hi fellows: I'm trying to mount PHP5 ( the last stable version from php.net) under a IIS6 (win2k3 SP2), and when I run the .msi and it finish it said that is not possible the configure httpd.conf, which is a very big mistake 'cause I'm specify that I use IIS6. After that I try making a manual configuration and I recive a CGI error. I need help ASAP. Este correo ha sido enviado desde el Politécnico de Informática "Carlos Marx" de Matanzas. "La gran batalla se librará en el campo de las ideas" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|||
|
Hi how would I trigger another script whilst the parent continues without
waiting for the second script to finish. ie in the example below if db empty, start second script but also continue closing connections and exiting. if(sqlite_num_rows($result) == 0) { // trigger another php script sqlite_close($db); socket_close($sock); exit; } Thanks ----- Original Message ----- From: "Alberto García Gómez" <alberto@ipimtzcm.rimed.cu> To: <php-general@lists.php.net> Sent: Monday, October 08, 2007 2:57 PM Subject: [php] PHP5 under IIS6 > Hi fellows: > > I'm trying to mount PHP5 ( the last stable version from php.net) under a > IIS6 (win2k3 SP2), and when I run the .msi and it finish it said that is > not possible the configure httpd.conf, which is a very big mistake 'cause > I'm specify that I use IIS6. > > After that I try making a manual configuration and I recive a CGI error. > > I need help ASAP. > > Este correo ha sido enviado desde el Politécnico de Informática "Carlos > Marx" de Matanzas. > "La gran batalla se librará en el campo de las ideas" > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > |
![]() |
| Thread Tools | |
| Display Modes | |
|
|