Wednesday, September 9, 2015

How to connect Android Application with Microsoft SQL Database using PHP and retrieve data. (Section 1)

Section 1 I’ll discussed how to create odbc connection and write php code to get information from database to URL.

Part I: Create an ODBC connection.

Start MSSQL server Management studio.

Select SQL Server Authentication, Login Username and Password. Click Connect.


Left Side panel you can see Databases you created already.

Open the Administrative Tools icon in your Control Panel.




Double-click on the Data Sources (ODBC) icon inside.




Choose the System DSN tab and Click on Add in the System DSN tab.



Select the SQL Server Driver. Click Finish.




In the next screen, give Data Source Name. (This is very important. You should remember this) and select your sql server.



Select second radio button. Give Login ID and Password (It should be same as your SQL server Login ID and Password)

If you connect with MSSQL server using Windows NT authentication, Select first radio button. Then you don’t need to give any username or password.



 Click Next and choose Database.



Click Next and then Finish.
Then it appears Test Data source window.


If you successfully connect, you will able to see this prompt.



----------------------------------------------------------------------------------------------------

Part II: write PHP code to retrieve information from MSSQL Server

Start wamp server. Go to www folder and create new folder and rename it.create .php file inside that folder and write below code into it.

The odbc_connect() function is used to connect to an ODBC data sourceThe function takes four parameters: the data source name, username, password, and an optional cursor type.
The odbc_exec() function is used to execute an SQL statement.
The following example creates a connection to a DSN called “firstsql”, with my username and password.and also I wrote sql query to select information from Dept table which located in AndroidAppDB database.
Json encode is used to encode data to Jason array.

After that run http://localhost:81/my%20project/first.php.You will able to see this.




Next section I’ll create android app to get information from this URL. To be continuing…

7 comments:

  1. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Java training in Chennai

    Java training in Bangalore

    ReplyDelete
  2. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
    rpa training in bangalore
    best rpa training in bangalore
    RPA training in bangalore
    rpa course in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  3. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing..
    Believe me I did wrote an post about tutorials for beginners with reference of your blog. 




    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  4. Really great post, Thank you for sharing This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up!
    AWS Training in pune
    AWS Online Training

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete