php框架与mssql服务器结合探索之路(php-mssql)

recently,we had a task that it needs to connect php framework to the mssql server, so it’s time to explore the way to combine php framework and mssql. As an important open source web application for programming language, the most common php framework are thinkphp,laravel,phpcms, which supports different versions of mssql.

There are different methods when combing php framework and mssql.In general, firstly, you should install the mssql driver in the parameters folder of the php framework you are using.In order to designing database, you should create the object name, user name and password, the port of mssql database. Therefore, you need to confirm the appropriate mssql configuration and start the connection with the databases use the api. And then you can get the specific works done such as creating the data tables and inserting data into it.

Here’s an example of connecting php frameworks and mssql. When using laravel for introducing mssql database, you should download the sqlsrv driver.The code is as follows:

//Replace the database properties accroding to your configurations

$dbname = [Database name];

$servername = [Server name];

//Connecting database

$conn = sqlsrv_connect($servername, array(

‘Database’ => $dbname,

‘UID’ => ‘sa’,

‘PWD’ => ‘yourpassword’

));

//Check the connection is established or not

if ($conn ==false) {

echo “Error in connection.\n”;

}else{

echo “connected”;

}

sqlsrv_close($conn);

In conclusion, the exploration on combining php framework and mssql seems a bit complicated for the first time, but with more and more practice and usage, we can learnt to master this skill and skill and conquer the database field!


数据运维技术 » php框架与mssql服务器结合探索之路(php-mssql)