<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eyedbits &#187; php</title>
	<atom:link href="http://www.eyedbits.com/?feed=rss2&#038;tag=php" rel="self" type="application/rss+xml" />
	<link>http://www.eyedbits.com</link>
	<description>links, tutorials and code fragments regarding computer graphics</description>
	<lastBuildDate>Sat, 23 Jun 2018 05:45:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>How to expose data from a mysql database via php/JSON for access via HTTP</title>
		<link>http://www.eyedbits.com/?p=134</link>
		<comments>http://www.eyedbits.com/?p=134#comments</comments>
		<pubDate>Wed, 18 Jul 2012 13:46:22 +0000</pubDate>
		<dc:creator><![CDATA[busk]]></dc:creator>
				<category><![CDATA[general coding]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.eyedbits.com/?p=134</guid>
		<description><![CDATA[Situation: You got some (client) application, that needs data from a mysql database. The application cannot connect to the database itself. It sends a HTTP GET/POST request to a webserver, that gets the data out of the mysql database and &#8230; <a href="http://www.eyedbits.com/?p=134">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong>Situation:</strong><br />
You got some (client) application, that needs data from a mysql database.<br />
The application cannot connect to the database itself. It sends a HTTP GET/POST request to a webserver, that gets the data out of the mysql database and packs it into a JSON Array. This JSON Array is sent back to the client.</p>
<p><em>(Follow up situation, the client has to request and parse the data)</em></p>
<p><strong>What you need:</strong></p>
<p>&#8211; mysql database<br />
&#8211; webserver with php</p>
<p>This is the php code for the webserver (inspired from <a href="http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/8339-connect-android-mysql-database-tutorial.html" title="Basic 4 Android Forum" target="_blank"></a>)</p>
<div class="smallSourceCode">
<pre class="brush: php; title: ; notranslate">&lt;?php
  // connect to Database
  // database specifications, adapt your configuration
  $dbUri = &quot;...&quot;;
  $dbUser = &quot;...&quot;;
  $dbPassword = &quot;...&quot;;
  $dbDatabaseName = &quot;...&quot;;

  // establish connection
  $db = mysql_connect($dbUri, $dbUser, $dbPassword) OR
        die(mysql_error());

  mysql_select_db($dbDatabaseName, $db) OR
        die(mysql_error());

  // example query, adapt to your needs
  $sqlquery = &quot;SELECT ... FROM ... WHERE ... ORDER BY ... ASC;&quot;;
  
  $result = mysql_query($sqlquery) OR
        die(mysql_error());
  
  if (mysql_errno()) {
    header(&quot;HTTP/1.1 500 Internal Server Error&quot;);
  } else {
    $rows = array();
    // fill array
    while($r = mysql_fetch_assoc($result)) {
        $rows[] = $r;
    }
    // encode array as JSON and print it
    print json_encode($rows);
  }
?&gt;</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.eyedbits.com/?feed=rss2&#038;p=134</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
