Page 1 of 1

SQL/User API?

PostPosted: Tue Jul 03, 2012 9:53 pm
by nizchetus
Maybe this was answered somewhere, but searching "SQL" brings back no results.

It seems like this is managed with SQL, but where are the databases? I have mySQL installed on my server box, but I'm seeing no entries at all. Is it stored in it's own little server? Is it stored off-site?

I'm running 4.7.beta2 (build 3011) on a headless Ubuntu 12.04 box, and I'd like to use the user login for a website where I'll be making a blog and forum, instead of having my users create two accounts, I'd like to grab the user data from the Subsonic SQL database, or if there isn't one... then some sort of API to allow PHP login from an off-site webserver?

Anyone know if this is possible?

Re: SQL/User API?

PostPosted: Tue Jul 03, 2012 10:20 pm
by BKKKPewsey
Subsonic uses HSQL

:mrgreen:

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 5:57 am
by hakko
You can access the database through http://yourserver/db.view

select * from user

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 1:25 pm
by nizchetus
Awesome. Making progress. I've never worked with HSQL; is there a way I can access it through PHP?

Normally, with mySQL, I do a
Code: Select all
mysql_connect('host','user','pass');
mysql_select_db('dbname');

But I assume that only works with mySQL.

And, if there is a way to do that, what port would I use to connect to the HSQL? I assume that I can't use the web-front port.

E: Or, better yet, some way to keep the mySQL DB synced with Subsonic's HSQL DB, and then just pull all data from MySQL.

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 1:43 pm
by hakko
It seems like people have tried (even though PHP+HSQL feels awkward): http://stackoverflow.com/questions/2204 ... p-question

Why don't you use the Subsonic XML/JSON API instead? It exposes methods to get/create/delete users. http://www.subsonic.org/pages/api.jsp

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 1:44 pm
by nizchetus
hakko wrote:It seems like people have tried (even though PHP+HSQL feels awkward): http://stackoverflow.com/questions/2204 ... p-question

Why don't you use the Subsonic XML/JSON API instead? It exposes methods to get/create/delete users. http://www.subsonic.org/pages/api.jsp

I'll give it a shot, I'm just sort of new to web developing, so I really only know HTML/CSS and PHP with any reasonable quality. Was trying to stick with what I know. Thanks.

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 1:56 pm
by hakko
I think that connecting to a REST web service from PHP will give you no headaches compared to the HSQL idea. You'll find tons of examples on how to do it. Good luck!

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 4:41 pm
by nizchetus
Yeah, I'm stumped. I'm getting nothing. curl_exec is returning no content.

Code: Select all
$url = "http://{$subserver}/rest/getUser.view?u={$username}&p={$password}&username={$username}&v=1.8.0&c={$appID}";

$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, 0);
$result = curl_exec($c);
curl_close($c);

echo $result;


The url itself looks fine. In the web browser, it returns:
Code: Select all
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0">
<user username="xxxxxx" email="xxxxxx@xxxxxx.com" scrobblingEnabled="false" adminRole="true" settingsRole="true" downloadRole="true" uploadRole="true" playlistRole="true" coverArtRole="true" commentRole="true" podcastRole="true" streamRole="true" jukeboxRole="true" shareRole="true"/>
</subsonic-response>


I admit I've never used XML, but according to everything I've read... this should work. And it does work, with other random XML files I found on the web.

E: it might have something to do with the face that it's not an ".xml" file. or any sorta extension. Not sure how to make it work though, still.

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 5:09 pm
by hakko
You might get better help at a PHP forum if nobody pops up here...

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 6:10 pm
by nizchetus
hakko wrote:You might get better help at a PHP forum if nobody pops up here...

I asked over at stackoverflow... they've got a good base of programmers/designers there. Hopefully I can get an answer soon. It'd be an awesome functionality to have. Maybe I can just convert everything over to OpenID, if I figure out how to edit the webfront login.

Thanks for your help.

Re: SQL/User API?

PostPosted: Wed Jul 04, 2012 10:33 pm
by nizchetus
Update: Found out that PHP doesn't like grabbing XML from port 4040. Had to change my port, but it works now.

Re: SQL/User API?

PostPosted: Thu Jul 05, 2012 7:16 am
by hakko
Nice. Thanks for sharing the solution!