Connect ionic app to MS SQL server 2008 with PHP

Hi,

I am working on a project that will require my app to connect to a Microsoft SQL server 2008 database.
I cannot seem to find a decent walk through or code to help me make this connection. I have tried a few different methods including ajax and PHP … does any one have a working example I can see or a link to a basic walk through that might help me?

I appreciate any advice people can give

Code below…

Thanks

Thomas

I am trying to use $http to get within my controller:

$http({ method: 'GET', url: 'app/attendance/index.php' }).success(function (response) {
    $scope.names = response;
});

my php looks like this:

<?php $serverName = "myServerName\sqlexpress"; //serverName\instanceName $connectionInfo = array( "Database"=>"Mobile_App_Test", "UID"=>"userName", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); //declare the SQL statement that will query the database $query = "SELECT * FROM Attendstu"; //create an array $emparray = array(); while($row =sqlsrv_fetch_assoc($result)) { $emparray[] = $row; } //write to json file $fp = fopen('app/attendance/testJson.json', 'w'); fwrite($fp, json_encode($emparray)); fclose($fp); //close the db connection mysqli_close($connection); ?>

It seems that the controller never enters the php file. I have added a break point to the connection string but it doesnt make it that far.

Has anyone any idea?

Thanks again

Here’s my suggestion:

  1. Try to check your URL if correct
  2. If it’s correct then try to create a simple function like test() (for test purposes)
  3. Call it on your ajax request like this app/attendance/index.php/test/

BTW sir. I’m using codeigniter that’s why i don’t have a proper knowledge on that situation.

Hi!
barbadillojomel: You can use codeigniter with ionic?

Yup sir. Just extract it in your server then connect it to the database. Do a controller that fetch the data from the model.
In controller:

UserController.

public function fetchData()
{
//Call the data from the model
}

In your: Ajax

app/attendance/index.php/UserController/fetchData/

1 Like

Are you testing from device or browser? If from device, you need to supply the full url for example

http://www.mydomain.com/app/attendance/index.php

Greets

1 Like