0

i've a question...i want to use a mysql database and connect it to my android app, i wish to connect it and copy on sdcard and so every time that app starts i want to check version of mysql database. how can i check version of mysql database? i can't find anything about this... i connect to database by a php script like this:

<?php
//Connect to database and select it
mysql_connect("127.0.0.1","root","");
mysql_select_db("database");
//query
$sql=mysql_query("SELECT * FROM table");
//put all into an output
while($row=mysql_fetch_assoc($sql))
    $output[]=$row;
//print json object
print(json_encode($output));
//close database
mysql_close;
?>
laalto
  • 150,114
  • 66
  • 286
  • 303
tafazzi87
  • 69
  • 2
  • 6
  • possible duplicate of [How to know the version of the MySQL database?](http://stackoverflow.com/questions/8987679/how-to-know-the-version-of-the-mysql-database) – Huey Jan 13 '14 at 11:03
  • do you want to know, if your data in the database is newer than your copy on the sdcard ? – sqlab Jan 13 '14 at 11:33
  • yeah i want to know if my data on my database is newer of my copy on sdcard – tafazzi87 Jan 13 '14 at 13:58
  • 1
    then there are e.g. two ways 1, compare the timestamp of the file on your sdcard with the timestamp of your db or 2, use a table with just one field and one row, where you store a version number of the last update/insert/delete and compare this. If it's different, delete your old file on the sdcard and write a new with the name of your version – sqlab Jan 13 '14 at 14:07
  • thanks this answer is that what i want!!! – tafazzi87 Jan 13 '14 at 14:17

5 Answers5

2

You can try this query

SELECT VERSION();

Also you can check this for reference

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
1

Pretty simple.

SELECT VERSION();

Output (in my case):

+------------+
| VERSION()  |
+------------+
| 5.1.69-log |
+------------+
Ryan
  • 3,552
  • 1
  • 22
  • 39
1

Just need to try SELECT VERSION();

For more details on DB,

SHOW VARIABLES LIKE "%version%";

Duplicate of How to retrieve the current version of a MySQL database?

Community
  • 1
  • 1
Surabhil Sergy
  • 1,946
  • 1
  • 23
  • 40
1

then there are e.g. two ways
1, compare the timestamp of the file on your sdcard with the timestamp of your db or

2, use a table with just one field and one row, where you store a version number of the last update/insert/delete and compare this.

If it's different, delete your old file on the sdcard and write a new with the name of your version –

sqlab
  • 6,412
  • 1
  • 14
  • 29
0

Try this.

while($row=mysql_fetch_assoc($sql))
$output[]=$row;
.
.
$ver = mysql_query('SELECT VERSION()');

$version=mysql_fetch_assoc($ver);
$output[]=$version;
.
.

print(json_encode($output));

If you want to get result from the same mysql server every time, just select version one time store it in the session or cookie and encode that value into json format.