Reputation: 2387
Note: I'm a PHP-noob.
I have a PostgreSQL database running on my server. I just created all my tables and inserted some test data.
I want to execute a query and create a result in XML so my Android Application can read it. First I wanted to create the xml manually but I came across this question and I read Mapping Tables to XML. I only didn't find any examples/tutorials for this function. I tried this:
$query = "SELECT * FROM query_to_xml('SELECT * from class_levels',true,false,'')";
$rs = pg_query($con, $query) or die("Cannot execute query: $query\n");
But I keep getting errors:
Warning: pg_query(): Query failed: ERROR: function query_to_xml("unknown", boolean, boolean, "unknown") does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts. in /home/.../cms/index.php on line 18
Cannot execute query: SELECT * FROM query_to_xml('SELECT * from class_levels',true,false,'')
What am I doing wrong? And does anyone have some good examples for this function?
Upvotes: 0
Views: 1537
Reputation: 45910
postgres=# SELECT * FROM query_to_xml('SELECT 1 as foo',true,false,'') x; x ─────────────────────────────────────────────────────────────── <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">↵ ↵ <row> ↵ <foo>1</foo> ↵ </row> ↵ ↵ </table> ↵ (1 row)
Your query looks well, so probably you use too old PostgreSQL version without xml support. What pg do you use?
Upvotes: 2