开发者

Installing MSSQL functions in PHP

开发者 https://www.devze.com 2023-03-28 19:07 出处:网络
I\'m trying to connec开发者_JAVA技巧t to my SQL server through PHP. Obviously using MySQL php functions do not work, how do I go about installing MSSQL functions for PHP on OSX? After exhausting googl

I'm trying to connec开发者_JAVA技巧t to my SQL server through PHP. Obviously using MySQL php functions do not work, how do I go about installing MSSQL functions for PHP on OSX? After exhausting google, I thought there would be a lot more tutorials are resources available which suggests to me this isn't the best way to connect to an SQL server.

Thank you in advance!


Example:

function read($id){
$myServer = "xx.xx.x.x";
$myUser = "us";
$myPass = "pas";
$myDB = "db";


//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer");

$dbhandle =  mssql_select_db($myDB,$dbhandle);

echo "Connected";

//declare the SQL statement that will query the database
$query = " SELECT col1 from table1";

//execute the SQL query and return records
$result = mssql_query($query) or die("Couldn't execute query");

$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" .$numRows. ($numRows == 1 ? "" : "s") . " Returned </h1>";

//display the results
while($row = mssql_fetch_array($result))
{
...
}


//close the connection
mssql_close($dbhandle);
}

For further detail, see this link

http://php.net/manual/en/book.mssql.php


ps: mssql (at least 5 years ago) was a lot slower than mysql in doing simple stuff(SELECT/INSERT/UPDATE). mssql had the advantage of views and pretty human stored procedures... but speed was more important...

  • http://php.net/manual/en/book.mssql.php
  • http://php.net/manual/en/book.uodbc.php

Disclaimer: never used them

What have you tried until now?


From the PHP Manual...

To use the MSSQL extension on Unix/Linux, you first need to build and install the FreeTDS library. Source code and installation instructions are available at the FreeTDS home page: » http://www.freetds.org/

I have never even tried to do this but just had a look and it seems to be fairly comprehensively documented - although it does assume you know a little bit about building from source on *nix... You will also need gcc or similar...


You need to ensure that PHP has been compiled with MySQL support, or that you have enabled the MySQL extension. You can check your PHP.ini file to determine if you need to uncomment those lines or not. Usually this is the case.

0

精彩评论

暂无评论...
验证码 换一张
取 消