Mysql-- Getdate--now

erdemirerkan

Member
Licensed User
Longtime User
Hi friends,

How can i get server's datetime using mysql function in my server. I want to use "select now()"

What do i write after executeremotequery(.....................................,......)
and how can i get it ?

Thanks,
 

erdemirerkan

Member
Licensed User
Longtime User
OK,
I wrote this code. But i couldn't write CASE section in responsesuccess . What can i write in it ? Sorry my english.

Select TaskId
Case 1
..
..
..
..
End Select
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
To get a concrete answer you must give more information.
At least the code of the whole subroutine.
Do you get any error message ?
Did you look in the Log Tab in the lower right corner in the IDE for a message?

You could eventually replace
Select TaskID
Case 1
Case 2
Case 3
etc
by

If TaskID = 1 then
Else If TaskID = 2 then
Else If TaskID = 3 then
etc

Best regards.
 
Upvote 0

erdemirerkan

Member
Licensed User
Longtime User
What I will write down a question mark?

:BangHead::BangHead::BangHead:Dear friends I want to take server date/time. This is my code. What will i write down a question mark?:BangHead::BangHead::BangHead:

Sub Process_Globals
Dim hc As HttpClient

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
hc.Initialize("hc")
End If
degistir=0
Activity.LoadLayout ("Main")
ExecuteRemoteQuery("select now()",1)

Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2("http://....................../baglanti.php", Query.GetBytes("UTF8"))
hc.Execute(req, TaskId)
End Sub

Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim res As String
res = Response.GetString("UTF8")
res=res.SubString (8)
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)

Select TaskId
Case 1
?????????
???????
???????
???????
???????
End Select

End Sub
 
Upvote 0

kaplanerkan

Member
Licensed User
Longtime User
I think, he will only result of "select now()"


@Erdemirerkan
sadece "select now()" sorgulamasinin sonucunumuelde etmek istiyorsun?
 
Upvote 0

erdemirerkan

Member
Licensed User
Longtime User
I understand that,
we can get only data from mysql, we can not use MYSQL datetime functions using Basic4Android. This is very bad situation.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
The attached example does what you're looking for.

The PHP on your server should be something like this:
PHP:
<?php
    $DB_HOST = "xxxxxxxxxx";
    $DB_USER = "xxxxxxxxxx";
    $DB_PASSWORD = "xxxxxxxxx";
    $DB_NAME = "xxxxxxxx";

     mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or die("Unable to connect to database! Please try again later.");
     mysql_select_db($DB_NAME) or die("Can't select Database ") . mysql_error();

     $query = "SELECT NOW()";

     $result = mysql_query($query);

     echo mysql_result($result, 0); 

?>

If you want to use the PHP above, save it as "Time.php"
 

Attachments

  • GetMySQLTime.zip
    6 KB · Views: 359
Last edited:
Upvote 0

erdemirerkan

Member
Licensed User
Longtime User
I try this code.But give error.Error is underline this text

41rkv.png
[/url][/IMG]
 
Upvote 0

erdemirerkan

Member
Licensed User
Longtime User
Questions for you:

Q1- Did you upload the PHP to your server?
A1- Yes i uploaded and i try it. Php file shows datetime in windows in web browser but mobile phone does not show.

Q2- Did you name the PHP Time.php?
A2-Yes i named it

Q3- Did you change the link to your server in the B4A sample?
A3-Yes i changed it

Is there any problem about android version ? I use android 2.2
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Well, if you see the date-time on your Windows desktop that means the PHP script works, and if that works the Android app should too, I tested both codes before uploading and I get the result on a MsgBox.

If you want, upload your project, from the designer click on File -> Export to ZIP.
 
Upvote 0
Top