0

I am developing Smoking counter and I need to send all the smoking record (about the time user smoking) to database on the server. The server database is MySQL database. I knew that I must have send data to PHP page/script, and this page/script will run on the data to insert record to database.

I would like to know: is there another way to update database, because I don't have knowledge about PHP. I used to work on java and c/c++/objective-c. If you know another way to do this task, please let me know.

Any help would be appreciated.

3 Answers 3

2

If you already know Java, C and C++, then you should be able to learn how to write your php script really quickly, just google a tutorial.

While could run a Java server using a servlet to insert the data, PHP is far easier to deploy, and you should only need to write a few lines of code.

I you do use PHP though one thing to remember when inserting to your database is to run all your parameters to add through mysql_real_escape_string

Edit: To give an example, this script when configured would insert a name and location to a database:

<?php
$link = mysql_connect("hostname", "username", "password");
mysql_select_db("databasename");
$location = mysql_real_escape_string($_POST['location']);
$person = mysql_real_escape_string($_POST['person']);
mysql_query("INSERT INTO mytable(location, person) VALUES('{$location}', '{$person}')");
mysql_close($link);
?>
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I can learn PHP to write some script. But I would like to ask, after I write the PHP page/script, where can I upload that page because the database is on server. Do I need to upload that page on the same server? Sorry because this is maybe a stupid question.
Your PHP script would need to run on a server running PHP. If the DB is on a remote server then the DB server would need to allow remote connections, which is generally not a good idea unless you know what you're doing due to mysql injection attacks.
Your php has to be on a webserver that supports php. Your database can be in a different server(doesn't have to be on the same server that php is in). You just have to set up the php mysql_connect so that it points to the database server. Web servers that support php - LAMP(Linux), WAMP(Windows)
1

You may use any server side solution you like which has a MySQL interaction class library, e.g. Java servlet or C/C++ CGI application. You will also need a web server (e.g. Apache or Apache Tomcat) which will take care of HTTP requests.

PHP is not the only way to write programs which use MySQL.

Comments

1

You can you this API hosted on github.com .

https://github.com/gwdp/Obj-c-MySql

It's free and very well documented .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.