MySql database for app iOS and Android

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

aebki
Posts: 126
Joined: Tue Jan 06, 2015 5:48 pm

MySql database for app iOS and Android

Post by aebki » Tue May 19, 2015 11:37 am

Hi,

After some months disappeared, i will try to finish my app.
So, the first thing i made is to create one account to can have one database in cPanel.

Once this is done, i would like to know how to connect with the database from my app (that should work for iOS and Android)?
The database is one MySql.

Thanks in advance!

Regards.

Klaus
Posts: 11108
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: MySql database for app iOS and Android

Post by Klaus » Tue May 19, 2015 12:15 pm

Hi aebki
aebki wrote:... i would like to know how to connect with the database from my app (that should work for iOS and Android)?
just like the first example in the dictionary about "revopendatabase" suggests! 8)

Be aware that most providers do NOT allow direct (your app <-> mysql) connection
to your database but require a "middle-ware" like PHP or Livecodes Server (your app <-> PHP/LC Server <-> mysql)!


Best

Klaus

aebki
Posts: 126
Joined: Tue Jan 06, 2015 5:48 pm

Re: MySql database for app iOS and Android

Post by aebki » Tue May 19, 2015 1:20 pm

Hi Klaus,

Thanks for your answer.

What does it mean the middle-ware???
I don't understand very well...When i asked what should i do to can have my database online, some months ago, for my app; it was suggested to me to have one account in on-rev to can host my database...
And now that i made this, it seems it is not enough...:-(
So, can you tell me please what and how should i do the things to can connect with the database from my app and use the data i have in this database?

And about the revopendatabse, i have one question:
I think i have to use this one:

get revOpenDatabase("mysql", "www.example.com", "RatesDB", myUsr, myPass)

So my doubt is what i have to put in place of the parameter "www.example.com"??? as i said before my database is created now in the cPanel in the on-rev.

Regards.

Klaus
Posts: 11108
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: MySql database for app iOS and Android

Post by Klaus » Tue May 19, 2015 1:32 pm

Hi aebki,

"middleware" means that your app will "connect" to a webservice like PHP or LC Server,
that webservice will connect to the actual database and will return/modify/update/delete
the records in the database.

As I said, you need to ask your internet provider/hoster if you can connect directly to your
database WITHOUT any middleware.

You need to replace "www.example.com" with the URL of your "home page", for me it would be "www.major-k.de" :D


Best

Klaus

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: MySql database for app iOS and Android

Post by sefrojones » Tue May 19, 2015 2:00 pm

I believe that there are example "middleware" scripts for both LiveCode server and PHP in this thread:

http://forums.livecode.com/viewtopic.ph ... re#p124505

--Sefro

aebki
Posts: 126
Joined: Tue Jan 06, 2015 5:48 pm

Re: MySql database for app iOS and Android

Post by aebki » Tue May 19, 2015 2:23 pm

Hi,

Thanks to both (Klaus and Sefro)!

My server is one from "on-rev".
As I said, you need to ask your internet provider/hoster if you can connect directly to your
database WITHOUT any middleware.
So, my hoster is the same one as the LiveCode (except if i am wrong)...Do you think that it will need one middleware anyway or not?

Regards.

Klaus
Posts: 11108
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: MySql database for app iOS and Android

Post by Klaus » Tue May 19, 2015 2:28 pm

Hi aebki,
So, my hoster is the same one as the LiveCode (except if i am wrong)...
Do you think that it will need one middleware anyway or not?
although I also have an ON-REV account, I have no idea, sorry.


Best

Klaus

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: MySql database for app iOS and Android

Post by sefrojones » Tue May 19, 2015 2:31 pm

I also have an on-rev account, but I'm also not sure if they allow direct connections. I think if you are going to be distributing this app to other users, then best practice would be to use some sort of middleware, as I believe it is more secure than hard coding your database credentials into the application.

--Sefro

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: MySql database for app iOS and Android

Post by Simon » Tue May 19, 2015 2:37 pm

Hi aebki,
Take a look here;
http://forums.livecode.com/viewtopic.php?f=53&t=20956
It's not a detailed explanation but if you look into the modules (phpadmin, Remote MySQL) you should be able to figure it out.
And yes this is all done on an on-rev server via cPanel.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

aebki
Posts: 126
Joined: Tue Jan 06, 2015 5:48 pm

Re: MySql database for app iOS and Android

Post by aebki » Tue May 19, 2015 3:16 pm

Thanks Sefro and Simon,

I would have like to be able to do what Sefro suggests me. But i am not sure i will be able...:-(

So, if it is as Simon said, it should work directly ( that it arranges me as i am not very very 'pro' with PHP ).

So when i create my account on 'on-rev' and i entered in cPanel first time, i had one message that i have one website: "www.mywebsite.on-rev.com" or something like this...then i created one database and one admin user.
So if i adapt what the dictionary says about revOpenDatabase:
revOpenDatabase("mysql", "www.example.com", "RatesDB", myUsr, myPass)


with
put 'myadminuser" into myUsr
put 'mypassword1234' into myPass

revOpenDatabase("mysql", "www.mywebsite.on-rev.com", "myDatabase", myUsr, myPass) it should work?

Regards.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: MySql database for app iOS and Android

Post by Simon » Tue May 19, 2015 5:59 pm

Hi aebki,
Yes, just set up the phpadmin and change the remote Mysql to your ip address or one of the wildcards (! or * I think).
I didn't have to do any php coding.

This works for on-rev only because they allow it, other hosts may not.
Oh, and I think internet security people frown on using this method but others will have to tell you about that.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

aebki
Posts: 126
Joined: Tue Jan 06, 2015 5:48 pm

Re: MySql database for app iOS and Android

Post by aebki » Tue May 19, 2015 6:31 pm

Hi Simon,

Thanks for your answer...I could do it! :-)
In fact in place of '*' it should be with '%'...

Then i tested the connection and i have one connection, as the answer of my tDatabaseID was 'something' ( in my case i had 'connection1' i think).
But after i tried this

Code: Select all

put revDataFromQuery(tab,return,tDatabaseID,"SELECT Name FROM Members ") into theResult
answer theResult
But i have no answer...So, what am i doing wrong in my sql?

I created one table named "Members" with some columns. The first one (the primary key) is "Name".
And then i filled info...So, in "Name" i should find "aebki"...But i am not arriving here...:-( I think i have one problem in my "SELECT"...

Regards.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: MySql database for app iOS and Android

Post by Simon » Tue May 19, 2015 6:54 pm

Hi aebki,
Check out this lesson
http://lessons.runrev.com/m/4071/l/1659 ... grid-array
For a mysql connection you have to convert database cursor into an array.
tDatabaseID should just be a number.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

SparkOut
Posts: 2015
Joined: Sun Sep 23, 2007 4:58 pm

Re: MySql database for app iOS and Android

Post by SparkOut » Tue May 19, 2015 7:04 pm

Name is a reserved word, I believe. Enclosing it in backticks might be the answer.

aebki
Posts: 126
Joined: Tue Jan 06, 2015 5:48 pm

Re: MySql database for app iOS and Android

Post by aebki » Tue May 19, 2015 8:34 pm

Hi,

Thanks to both! :-)

So i changed "Name" for one "MyName".
And yes Simon, you are right what i have is one number in my connection...First i told you connection 1, because in fact what i told you is what i had in my answer ( answer "connection" & tDatabaseID ).

And i looked at the lesson you told me...And i think this i will need when i will use one dataGrid.

Now i am only trying to see if it is working the 'interaction with the database'...So how should i make one "SELECT count(*) from Members WHERE MyName='aebki' "???

Regards.

Post Reply

Return to “Databases”