Get data from SQL Server

Discussion in 'Android Questions' started by junaidahmed, Dec 29, 2010.

  1. junaidahmed

    junaidahmed Well-Known Member Licensed User

    Can I access SQL Server data from Server to Device in Basic4Android?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You will need to create a (simple) web service that runs on the server and handles the requests.
    Then you can use the HTTP library to send and receive data.
     
  3. junaidahmed

    junaidahmed Well-Known Member Licensed User

    i am new for developing application in basic4android,pls advise how to create webservice in server,awaiting for your replay
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You can for example create a PHP script that gets the query in the POST parameters and prints the results in some format which you can parse.
    The web service cannot be built with Basic4android.
     
  5. junaidahmed

    junaidahmed Well-Known Member Licensed User

    I dont't know how to create webservice,I want to display SQL server 2000 record in my android devices.please explain step by step procedure.Eagerly awaiting for your replay
     
  6. alfcen

    alfcen Well-Known Member Licensed User

    Hello,

    You need to write a PHP script and upload it to your server where the database resides.
    The PHP script queries the database and returns a given result. The format of the result
    is your choice, preferrably CSV, HTML or XML.

    Use the HTTP library to address the URL of the PHP script on the server with query parameters, such as

    Code:
    http://www.myserver.com/query.php?table=products&where=material&type=iron
    The PHP script should then generate an sql query, something like

    Code:
    SELECT from " . $table . " WHERE " . $material . " = iron"
    The PHP script will then return all items that match the query in either of CSV, HTML or XML.

    This data will then be received by the HTTP library in return to the URL request above
    and need to be parsed appropriately to obtain the desired display for the Android.

    Sorry, I can offer a mere rough guide, since such a project depends on too many individual details,
    which only you know.

    If in doubt about how to write in PHP/Sql, please try and get help from your friends or colleagues in your vicinity.
    PHP/Sql issue lie beyond the scope of B4A support.
     
  7. junaidahmed

    junaidahmed Well-Known Member Licensed User

    Thanks for your quick replay
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    JSON format could also be used in both sides.
     
  9. junaidahmed

    junaidahmed Well-Known Member Licensed User

    Error Connecting to Server

    As per your opinion I have wrote a PHP script and upload it to our server and the format of the result is html format,the result works fine in the browser,but when execute the HttpRequest (from http Library) it shows an error

    "Error Connecting to Server Java.net.unknownHostException : www.kharind.com"

    My Code is :

    Dim request As HttpRequest
    Dim URL as String
    URL = "http://www.kharind.com/experiment/Test.php"

    request.InitializeGet(URL)
    request.Timeout = 10000 'set timeout to 10 seconds
    If HttpClient1.Execute(request, 1) = False Then Return

    Please advise how to do this,Eagerly awating for your replay.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Does it work if you enter the ip address instead of the host:
    http://xxx.xxx.xxx.xxx/Test.php

    Does it work with other hosts? Try to connect to google for example.
     
  11. junaidahmed

    junaidahmed Well-Known Member Licensed User

    Thank you,it works fine now
     
  12. gemasoft

    gemasoft Member Licensed User

    Sql Server Php

    Here an example for access to php with odbc and apache.
    First is important install the sql driver for php from microsoft site. After if the php extension is ok. you can test this code for retrieve a SQL SELECT statement.
     

    Attached Files:

    Last edited: Aug 23, 2011
    gasdav00 likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice