how to connect to database from iOS app? - mysql

i am beginner in databases and Xcode programming.
i am now installed mysql database, phpmyadmin and Seguel pro for testing.
i created new database and table with phpmyadmin. with segue pro i am connected to database and everything works.
now, i want to connect to this database to read all data to nsarray to show them in tableview. my host is 127.0.0.1, username is "ssebastijan", password is "password", database name is "sebastijan", table name is "test" and port is 3306.
can somebody post code for connection, or explain me how to connect. i already trying two days goggling, but i can't find answer.
thank you!
Greetings from Croatia. Sebastijan Sakač

I don't think it is a good idea accessing the database directly. Using a web service (REST) on the server and accessing the web service from the iOS client is not only common but highly recommended. You can, however, access mysql diretly as you would do in any plain C program. Here is an expample. http://blog.iosplace.com/?p=30

Related

How do I connect my Android Application to a MySQL database stored in a server?

Background on the MySQL database: it was created from a Wordpress website. As far as I know, it can only be accessed through PuTTy with the ff credentials given to me by my client who I’m making the app for:
hostname
port
my username to get into server
my password to
get into server
mysql username
mysql password
It says from multiple sites that this is the PHP syntax to connect Android to MySQL
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
It does not work and when checked for the connection error, it shows the error “Connection timed out.” when I put credentials needed (hostname, mysql
username and password). I’m assuming it’s because I need to get into the server first (with credentials #3 and #4).
Is there a workaround to this?
EDIT:
This is only based on the assumption that I am supposed to create a PHP file (that I will place inside a Jave file in Android Studio) to connect to their database. Are there other ways to connect to a private server?
Welcome Ateshi!
It sounds like you want an android app to directly access the mysql database that holds the content of a wordpress website.
The MySQL database server is most likely not publicly available on the internet for good reasons (security), as per this answer
You have posted some PHP code. PHP usually runs on the server alongside mysql, it not usually run on android.
Here is how you usually set up something like this:
Your android app makes a web request to http://yourexampleserver.com/example.php
Inside that example.php which is on the server, you have the PHP code that then does:
connects to mysql (with local credentials)
perhaps writes to the database
perhaps queries the database
formats the results into a useful format like JSON
The results are returned to java on your android which then usually shows them in the UI etc
This whole process is usually described as building a "webservice" for the app to use.
If however, you want the database contents to be stored offline and locally on android, then you probably need to connect to the server manually, export the database and download it, and then include it in your android project.

Outsystems: configuring a connection to access a MySQL database

I'm using Outsystems Service Studio to develop a web application. I need to configure a connection to access a local server database. I get "Connection String test failed: Unable to connect to any of the specified MySQL hosts." I just figured out I can't connect using "localhost", because the Outsystems server is not local, but I'm not able to find a solution. what is wrong? Other details:
MySQL Server is up and running
I selected MySQL in DBMS
Inserted my schema name
Inserted the username (with all privileges granted)
Inserted the user password
Tried both basic and advanced configuration. I inserted j"dbc:mysql://127.0.0.1:3306/mydb?user=outsystems2" as connection string parameters and I get "Connection String test failed: Keyword not supported.Parameter name: mysql://127.0.0.1:3306/mydb?user". I know this connection string can't work , but I'm not able to find a functioning one. I've read many guides about this configuration, but no solution was found. Thank you all for your time and help, feel free to ask for more details
Luciano,
Is your OutSystems environment on-premises or in the cloud? Either way, you need to make sure that this server is able to reach - it as connectivity - to your MySQL database server. Using localhost or 127.0.0.1 is pretty much the same thing as this is an address for the machine where the request is running, which is, in this case, the OutSystems server. Do you have the MySQL database on your local machine? This is not a good approach as you will need to have an address that won't change otherwise the connection won't be stable and you'd have to reconfigure it all the time.
Regards

JDBC connection issue ubuntu and PHP Storm

Im trying to connect to the database using DB navigator in PHP Storm.
I can already connect to my database which is a VPS on digitalocean with php and PDO using localhost as the host and the username and password setup through PHPmyadmin. I don't understand why that works since my database is stored on Digital Oceans VPS but it works, i can write to and from the database no problem and access my database at www.mywebsite/phpadmin
normally when localhosts works it means i have LAMP installed on my local machine but i don't and when i worked previously with shared hosting for another site the host was the ip address.
Anyway i didn't worry about it since it works for my PHP connection but now im trying to use DB navigator with PHPstorm and it needs to setup the database connection. since im using the same username and password that works for php connection to the database i assume that is correct.
I have installed the driver library and selected the .com.mysql.jdbc.Driver as the driver.
for URL which i assume must be host i have tried the following:
pretend droplet ip = 123.456.789
pretend website is: www.mywebsite.com
jdbc:mysql://localhost:3306
jdbc:mysql://123.456.789:3306
jdbc:mysql://mywebsite.com:3306
jdbc:mysql://www.mywebsite.com:3306
None of these work and all say no packets received. I also tried with the data source option in php designer with the same results. Anyone know what the correct connection string is, maybe i have the string structured wrong, im new to ubuntu and these VPS systems, i have ssh access also if that matters?

Plesk not creating a New Database Server

I have a windows server where Plesk is installed with php & mySQL by default (from Hosting Provider). When I first got the server I remember I removed mySQL from Control Panel since I didn't need it, but after like one year, I came to a point where I have to create a Wordpress website, and therefore I am needing mySQL again.
Note also that there's two mySQL, one for Plesk (which I didn't uninstall), and another one for our databases (which I uninstalled long ago, but reinstalled later).
I went to Plesk under Database Servers, and I can see there's no Database Servers there... Then I try to Add Database Server with the following settings:
Hostname: localhost
Port: 3306
With Admin Username & Password...
But I am getting the following error:
Error: A database server with this combination of host address and port number is already registered.
Please note that this is surely different from the mySQL settings for Plesk since the port is different.
Do you guys have any idea how to resolve this issue? I've been stuck since a few days...
I appreciate your help guys that's urgent!
Thanks.
Looks like inconsistency in plesk database "psa" related to entity of database servers.
Most easy workaround it's to register new database server not as "localhost", but as "127.0.0.1" or some other name which can be resolved to localhost or other port.
Another workaround it's to look into psa database via "%plesk_bin%\dbclient.exe" --direct-sql --sql="select * from databaseservers".

What to send someone to access my mysql database?

I have a mysql database on my pc , what should i send someone to access it :S? A connection string or a live link .Is it possible?
Thank you
This worked perfectly for me. You're essentially giving them access to a separate installation of phpmyadmin that provides them access to any of the databases on your server via their separate database login credentials
Is your computer available to others through the Internet, or does your ISP block access through port 80 (HTTP)? If the other person can access a web server on your computer that person could admin your mySQL database through phpMyAdmin?
If the other person knows how to use a terminal to perform sql-tasks I guess you could grant this person permission (see: http://dev.mysql.com/doc/refman/5.1/en/adding-users.html).