Read SQL database from a webpage

Hello there,

i just create a database using coronium (Sql buddy) in a amazon aws server. The thing here is that i need to read the table in another webpage, for example to show a global ranking of the game in the official web page… or just to grab that data automatically, vía PHP or something similar i suppose. 

Thank you for your time. I really need your help.

Hi,

I’m sorry to say that the current version of Coronium does not  support public facing pages (admin-only). If you are trying to access your database externally from another system, that is something that you need to set up with MySQL to allow your connection.

The next version does support public facing pages as well as other facilities to interact with your data.

Ok thanks for the quick response!

If all you want to do is expose MySql data to your web-server then all you need to do is in Coronium create the cloud code to expose that data and then use Curl or your web-server language’s equivalent to call that endpoint. After all it is just JSON.

Example in PHP:

\<?php $curl = curl\_init(); curl\_setopt\_array($curl, array( CURLOPT\_URL =\> "http://{{YOUR CORONIUM URL}}/1/code/{{CLOUD CODE ENDPOINT}}", CURLOPT\_RETURNTRANSFER =\> true, CURLOPT\_ENCODING =\> "", CURLOPT\_MAXREDIRS =\> 10, CURLOPT\_TIMEOUT =\> 30, CURLOPT\_HTTP\_VERSION =\> CURL\_HTTP\_VERSION\_1\_1, CURLOPT\_CUSTOMREQUEST =\> "GET", CURLOPT\_HTTPHEADER =\> array( "cache-control: no-cache", "content-type: application/json", "x-coronium-api-key: {{YOU CORONIUM API KEY}}", "x-coronium-app-id: {{YOUR APP ID}}" ), )); $response = curl\_exec($curl); $err = curl\_error($curl); curl\_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }

Cloud code documentation for MySql can be found here: http://docs.coronium.io/en/latest/server/mySQL/

EDIT: Fixed URL (bad copy paste)

Hi Steven,

Maybe you can help…

I am trying to connect to my Coronium Cloud server from another server, I am getting NO Access-Control-Allow-Origin error in the browser.

I am using a javascript call…

 

Is there a way to config Access-Control-Allow-Origin to accept connections from my second server?

Thanks

Rui

Moved answer to https://forums.coronalabs.com/topic/63611-access-control-allow-origin/.

Hi there Steve,

i think you got the point, thanks! By the way, the link you posted is broken and i really need that cloud code. I will search more documentation about it, but if you have another link to it, i would appreciate it.

yatsenpava,

It was a bad copy paste, the URL is fixed now. 

Hi,

I’m sorry to say that the current version of Coronium does not  support public facing pages (admin-only). If you are trying to access your database externally from another system, that is something that you need to set up with MySQL to allow your connection.

The next version does support public facing pages as well as other facilities to interact with your data.

Ok thanks for the quick response!

If all you want to do is expose MySql data to your web-server then all you need to do is in Coronium create the cloud code to expose that data and then use Curl or your web-server language’s equivalent to call that endpoint. After all it is just JSON.

Example in PHP:

\<?php $curl = curl\_init(); curl\_setopt\_array($curl, array( CURLOPT\_URL =\> "http://{{YOUR CORONIUM URL}}/1/code/{{CLOUD CODE ENDPOINT}}", CURLOPT\_RETURNTRANSFER =\> true, CURLOPT\_ENCODING =\> "", CURLOPT\_MAXREDIRS =\> 10, CURLOPT\_TIMEOUT =\> 30, CURLOPT\_HTTP\_VERSION =\> CURL\_HTTP\_VERSION\_1\_1, CURLOPT\_CUSTOMREQUEST =\> "GET", CURLOPT\_HTTPHEADER =\> array( "cache-control: no-cache", "content-type: application/json", "x-coronium-api-key: {{YOU CORONIUM API KEY}}", "x-coronium-app-id: {{YOUR APP ID}}" ), )); $response = curl\_exec($curl); $err = curl\_error($curl); curl\_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }

Cloud code documentation for MySql can be found here: http://docs.coronium.io/en/latest/server/mySQL/

EDIT: Fixed URL (bad copy paste)

Hi Steven,

Maybe you can help…

I am trying to connect to my Coronium Cloud server from another server, I am getting NO Access-Control-Allow-Origin error in the browser.

I am using a javascript call…

 

Is there a way to config Access-Control-Allow-Origin to accept connections from my second server?

Thanks

Rui

Moved answer to https://forums.coronalabs.com/topic/63611-access-control-allow-origin/.

Hi there Steve,

i think you got the point, thanks! By the way, the link you posted is broken and i really need that cloud code. I will search more documentation about it, but if you have another link to it, i would appreciate it.

yatsenpava,

It was a bad copy paste, the URL is fixed now.