PHP  
downloads | documentation | faq | getting help | | php.net sites | links 
search for in the  
previousmhash_keygen_s2kmssql_bindnext
Last updated: Tue, 28 May 2002
view this page in Printer friendly version | English | Brazilian Portuguese | Czech | Dutch | French | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

LVII. Microsoft SQL Server functions

The MSSQL extension is available on Win32 systems only. You can use the Sybase extension to connect to MSSQL databases from other platforms.

These functions allow you to access MS SQL Server database. The extension requires the MS SQL Client Tools to be installed on the system where PHP is installed. The Client Tools can be installed from the MS SQL Server CD or by copying ntwdblib.dll from \winnt\system32 on the server to \winnt\system32 on the PHP box. Copying ntwdblib.dll will only provide access. Configuration of the client will require installation of all the tools.

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

Sis�llys
mssql_bind --  Adds a parameter to a stored procedure or a remote stored procedure
mssql_close -- Close MS SQL Server connection
mssql_connect -- Open MS SQL server connection
mssql_data_seek -- Move internal row pointer
mssql_execute --  Executes a stored procedure on a MS-SQL server database
mssql_fetch_array -- Fetch row as array
mssql_fetch_assoc --  Returns an associative array of the current row in the result set specified by result_id
mssql_fetch_batch --  Returns the next batch of records
mssql_fetch_field -- Get field information
mssql_fetch_object -- Fetch row as object
mssql_fetch_row -- Get row as enumerated array
mssql_field_length -- Get the length of a field
mssql_field_name -- Get the name of a field
mssql_field_seek -- Set field offset
mssql_field_type -- Get the type of a field
mssql_free_result -- Free result memory
mssql_get_last_message --  Returns the last message from server (over min_message_severity?)
mssql_guid_string --  Converts a 16 byte binary GUID to a string
mssql_init --  Initializes a stored procedure or a remote stored procedure
mssql_min_error_severity -- Sets the lower error severity
mssql_min_message_severity -- Sets the lower message severity
mssql_next_result -- Move the internal result pointer to the next result
mssql_num_fields -- Get number of fields in result
mssql_num_rows -- Get number of rows in result
mssql_pconnect -- Open persistent MS SQL connection
mssql_query -- Send MS SQL query
mssql_result -- Get result data
mssql_rows_affected --  Returns the number of records affected by the query
mssql_select_db -- Select MS SQL database
User Contributed Notes
Microsoft SQL Server functions
add a note about notes

11-Feb-2000 09:02

To access MS SQL from Unix you may use Sybase's OpenClient which happens to
work (depending on platform, 7.0 needs SP1 and big endian platforms have
trouble) or FreeTDS (www.freetds.org) which is still alpha-ish but
directly supports MS SQL.


21-Apr-2000 03:49

I have just finished setting up php4 with freetds to connect to a MSSQL 7
server.  I used freetds 5.0 and configured with --with-tdsver=7.0


07-Jul-2000 04:14

To compile PHP to support M$SQL on LINUX:
-Download FreeTDS: www.freetds.org
and compile as required. Make sure to compile with the correct version of the protocol (read the readme)
-Compile PHP with '--with-sybase=/usr/local/freetds' or wherever you put freetds.
PHP will now support both mssql_*** and sybase_*** from Linux.. enjoy!


24-Dec-2000 09:07

IMPORTANT NOTEs:
1. results sets are not supported, only the first result set can be
retrieved. for example:
  SELECT 1
  SELECT 3,5
Only the first result set can be fetch. Use a Union instead.
2. Each fetch to cursor will get a result set. Fetch a large quantity row
sets will raise the server's overhead on network. try other way instead.
3. The very usefull advantage of ADO is that muti-result set are
supported. the core function is sp_cursorxxxxx. You can use it with a
muti-record set support client. I'm very disapointed that PHP has not
support it now.


22-Feb-2001 12:03

Having trouble with pesky TEXT datatypes? Try the query 'set textsize
555555555;' to set the limit on how much a TEXT will return.

Symptoms of the problem are hanging web browsers and "FATAL: 
emalloc():  Unable to allocate -2147483648 bytes" errors in apache's
error.log


22-Feb-2001 07:12

> Having trouble with pesky TEXT 
> datatypes? Try the query 'set 
> textsize 555555555;' to set the limit 
> on how much a TEXT will return. 

I was trying to figure out why 555555555 works and not anything higher. 
Then it occured to me ... the machine in question has 512 MB of ram.  The
moral of the story is that you have to adjust the size to how much memory
you have and how much data you expect to come out of the database.


19-Apr-2001 03:01

on Linux,
FreeTDS are not support GB2312 charset, use Sybase-11.9.2 client tools is
ok.


13-Jun-2001 04:10

for anyone trying to connect to mssql on win nt using php4 if the options
listed here don't work try donloading the latest dll's for extensions. the
version 7 dll we tried to use would not work

21-Aug-2001 11:01
> Having trouble with pesky TEXT datatypes? Try the query 'set textsize
555555555;' 
> to set the limit on how much a TEXT will return.

I was indeed having troubles with those pesky TEXT datatypes, this query
alone didn't help either, i had to put 

mssql.textlimit = 65536
and
mssql.textsize = 65536

in php.ini and then restart _the WHOLE_ of IIS (not just the website) to
get it working (and don't forget to use that query too)

(That's on Win32 + IIS)


31-Jan-2002 09:19

Easy Oracle-Connection with my Class for Oracle/mySQL/MSSQL!
my cDBC-Klass is free and with Documentation and sources.

visit my Site: 


11-Feb-2002 05:05

Library php_mssql.dll is where has to be, but PHP cannot load it. SQL
Server drivers are installed and MSDE 2000 is running on my machine.

X-Powered-By: PHP/4.1.1 Content-type: text/html 
PHP Warning: Unable to load dynamic library 'c:\program
files\php\extensions\php_mssql.dll' - The specified module could not be
found. in Unknown on line 0 

The line of code I used, is the following:

<?
    $db =
mssql_connect("MyComp","myUserName","myPassword");
?>


21-Feb-2002 06:00

If you have some trouble with FreeTDS and TEXT limit (default 4096) and
set TEXSIZE doesn't work and you can't even use mssql_init to use stored
proc.

use a simple query with "exec stord_proced_name"..
and create the store proc with
set textsize ...
your data processing (like select...)
at the end enter
set textsize 0..

and it will work perfectly !!!!


15-Apr-2002 04:29

The belows procedures works on the following configuration: Mandrake linux
8.2,MS Sql server 2000, windows 2000 server, PHP ver 4.12, apache
1.3.24,Freetds 0.53. 

Configure Freetds
1.	Download Freetds 0.53 at www.freetds.org
2.	./configure --prefix=/usr/local/freetds --with-tdsver=7.0
3.	make
4.	make install
5.	Edit /usr/local/freetds/etc/freetds.conf
6.	Add
[MyServer70]              ��DSN for PHP
host =  10.23.52.114		 ��MS SQL Server IP
port = 1433				 ��MS SQL Default Port
tds version = 7.0			 ��MS SQL 2000 Version No.
client charset = UTF-8		 ��Charset Encoding, it can be omitted if you
don't want to disply in unicode

Configure PHP 4.12
1.	Download PHP4 from www.php.net
2.	./configure --with-sybase=/usr/local/freetds --with-apache=../{Apache
Path} --enable-track-vars
3.	copy all files in /usr/local/freetds/lib/ to /usr/lib
4.	make
5.	make install

Configure Apache 1.3.24
1.	./configure --activate-module=src/modules/php4/libphp4.a
2.	make
3.	make install
4.	cp php.ini-dist /usr/local/lib/php.ini
5.	Edit Your httpd.conf or srm.conf file and add;
AddType application/x-httpd-php .php
6.	/usr/local/apache/bin/apachectl start

Feel free to email to us @ [email protected] or [email protected]
German Chu & Eagle Lee


24-Apr-2002 08:36

Connecting to MSSQL 7 on UNIX/Apache/php4.1.2.  I followed a bunch of
instructions below from folks using Linux and other configurations...so
give this a try, it may work.

download freetds from www.freetds.org
configure arguments --with-prefix=/usr/local/freetds --with-tdsver=7.0

edit freetds.conf in /usr/local/freetds/etc/freetds.conf
[MyServer70]              
host =  XX.XX.XX.XXX(your MSSQL IP)
port = 1433
tds version = 7.0			 
client charset = UTF-8	

reconfigure PHP using --with-sybase=/usr/local/freetds/ and all of your
normal args.  

restart apache and it works...well it did for me.  Good luck

jd


05-Jul-2002 04:23

NEED HELP

having problems with php_mssql.dll
under MSWINDOWS 2000 and apache 1.3.24
if i enable the extension=php_mssql.dll the i receive an error message 

"mssl:Unable to initialize module"
"Module compiled with API=20010901,debug=0,thread-safety=1"
"PHP compiled with API=20020429,debug=0,thread-safety=1"
and if i disable extension=php_mssql.dll then i receive in my browser:

"X-Powered-By: PHP/4.2.1 Content-type: text/html 
Fatal error: Call to undefined function: mssql_connect()"

dONT KNOW WHAT TO DO
i think its my dll that its not working
where can i get the latest
thanks for your help
Please mail me to [email protected]
David

add a note about notes
previousmhash_keygen_s2kmssql_bindnext
Last updated: Tue, 28 May 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat Jul 6 00:05:55 2002 CEST