php教程

安装

The MSSQL extension is enabled by adding extension=php_mssql.dll to php.ini.

To get these functions to work, you have to compile PHP with --with-mssql[=DIR] , where DIR is the FreeTDS install prefix. And FreeTDS should be compiled using --enable-msdblib .

Warning

MS SQL functions are aliases to Sybase functions if PHP is compiled with Sybase extension and without MS SQL extension.

User Contributed Notes

MaxusR at yandex dot ru 17-Aug-2015 11:25
MS SQL with dynamic ports enabled installation:

Append to freetds.conf
[mssql]
host = <host>
instance = <instance>
tds version = 8.0

On the server side the SQL Browser service must be running and UDP 1434 port must be open for incoming connections.
sbonder at outlook dot com 05-May-2015 02:01
This is how I got it to work:
> Install the necessary packages for FreeTDS:
  sudo apt-get -y install freetds-bin tdsodbc unixodbc

> Configure FreeTD
  nano /etc/freetds/freetds.conf

> Create a server
 [sqlserver]
        host = <server_name>
        port = 1433
        tds version = 8.0

> You can now test whether you can connect to your MSSQL Server as follows - using the tsql command line tool:
  tsql -S <createdsevername> -U <username> -P <password> -D <chosen_database>

> You should get a message that looks similar to this:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Default database being set to <chosen_database>
1> quit

> Install a php extention:
apt-get install php5-sybase

> Check if mssql in available in you phpinfo
justnshalom at gmail dot com 09-Feb-2015 07:02
In Ubuntu Just you need to install
php5-sybase
sudo apt-get install php5-sybase
Done ...
Connect with this keyword
mssql_connect('Your IP/localhost','username','password','database');
Dave 25-Jan-2010 01:25
Linux users: I had to set the TDSDUMP and TDSCONFDUMP environment variables in my apache init script in order for freetds/mssql connections to work:

In my /etc/init.d/httpd file:
export FREETDSCONF=/usr/local/freetds/etc/freetds.conf
export SYBASE=/usr/local/freetds
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$SYBASE/lib
export TDSDUMP=/var/log/freetds/tdsdump-apache_log
export TDSDUMPCONF=/var/log/freetds/tdsdumpconf-apache_log

Make sure apache can write to the TDSDUMP directory.

(Using FreeTDS 0.82, PHP 5.2.9)
mirko dot steiner at slashdevslashnull dot de 29-Sep-2009 03:36
PHP msdblib niggle encountered

In configuring your new version of PHP to work with FreeTDS 0.82, you may encounter:
configure: error: Directory /usr/local/freetds-0.82 is not a FreeTDS installation directory
PHP tests for a FreeTDS installation by looking for files that FreeTDS no longer installs. To assure PHP that FreeTDS is installed, create two files where FreeTDS was installed e.g.:
$ touch /usr/local/freetds-0.82/include/tds.h
$ touch /usr/local/freetds-0.82/lib/libtds.a
The file that needs to be changed is used by autoconf when the distribution tarball is constructed. Cf. revision 1.13 of PHP source file config.m4. (12 June 2008)

(http://www.freetds.org/news.html)
jonatasvenancio at gmail dot com 03-Mar-2009 11:07
Finally i did it.

I could make the connection with MS-SQL:
1 - I downloaded the new version of ntwdblib.dll like we already saw at the others posts.
2 - I actived the php_mssql.dll in php.ini (the DLL must be in your extension dir)
3 - Restarted apache.
4 - Got my MS-SQL name instance (in my case was SQLEXPRESS because i was using MS-SQL Express Version and didn't change the default configuration).
5 - I did my connection file.

#################
<?php
$conn
= mssql_connect("ADMIN-PC\SQLEXPRESS", "usuario", "senha") or die ("erro ao conectar");

// Admin-PC is the name of my computer and SQLExpress is the name of MS-SQL Instance).
// usuario is a user that i created on SQL server with this command.
// SP_AddLogin 'user', 'password'
// after that i used this onde SP_AddUser 'user'
// you can change fot the user you want.
// I cound't use the defaullt user of MS-SQL, but with this one the connection worked.

?>

I hope this can help you.

Sorry for the english.
I'm brasilian.
Venancio
Matt Mason 09-Jul-2008 10:42
Had a problem compiling PHP with --with-mssql=/usr/local/freetds , kept saying that it wasn't a valid FreeTDS directory...

Check that when you install FreeTDS from source, that it actually puts the required files from the source directory to where the installation directory was specified, so to fix:

cp [tds source]/include/tds.h /usr/local/freetds/include
cp [tds source]src/tds/.libs/libtds.a /usr/local/freetds/lib

{in this example I installed FreeTDS to /usr/local/freetds}

This may make it a little easier for some else too.

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788