Using MS SQL server with PHP for my b4x backend

Mashiane

Expert
Licensed User
Longtime User
Hi there

Well, this should be interesting. I'm running a dedicated web server via an ISP. I've been curious in terms of how I can use Microsoft SQL Server as a backend for my b4x apps via php.

I've just managed to get the first things first, getting the db running and it checked via php.

Reproduction:
1. Downloaded and installed extensions from here, https://www.microsoft.com/en-za/download/details.aspx?id=20098. Installed these via IIS Manager. NB: php should be installed on your windows server.

2. Went through this example here, https://www.sitepoint.com/sql-server-php/ and got a Successfully Connected, the next step is creating CRUD statements and will see what will happen.

Let's explore...
 

sorex

Expert
Licensed User
Longtime User
The combination will work for sure, I'm using it here at work aswell as the data I need to (ab)use comes out of a package that's using MSSQL server.

Altho for personal projects I prefer mySQL since hosting costs are always cheaper for linux based servers.
 

Mashiane

Expert
Licensed User
Longtime User
The combination will work for sure, I'm using it here at work aswell as the data I need to (ab)use comes out of a package that's using MSSQL server.

Altho for personal projects I prefer mySQL since hosting costs are always cheaper for linux based servers.
That's nice. Im faced with having to use this for multiple projects. Sadly, the internet is so scarce about using this as MySQL is more famous with php. If you have some useful links that I could refer to I would be grateful. Thx,
 

sorex

Expert
Licensed User
Longtime User
not the cheapest around but I pay €27/year for my hosting package.

also unlimited databases but they cut in traffic(1Gb)/webspace(125Mb) to trim the price. never got the quoatas tho.

@Mashiane : you could use these global functions to make things easier

B4X:
function sendquery($mysql){
global $myconn;
$result=sqlsrv_query($myconn,$mysql,array(),array('Scrollable' => SQLSRV_CURSOR_KEYSET));

if($result===false){
    if(sqlsrv_errors()!=null){        echo $mysql."<br>".print_r(sqlsrv_errors());    }
}
return $result;
}

function getLastId() {
    $myid=getrows(sendquery("SELECT @@IDENTITY AS id"));
    return $myid[0][0];
}

function sql_escape($data) {
    return str_replace("'","''",$data);
}
 
Top