PHP: Microsoft SQL Server functions - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousmime_content_typemssql_bindnext
Last updated: Fri, 30 Aug 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

LVII. Microsoft SQL Server functions

Bevezet�s

These functions allow you to access MS SQL Server database.

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

K�vetelm�nyek

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.

Telep�t�s

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

Fut�sidej� be�ll�t�sok

Er�forr�s t�pusok

El�re defini�lt �lland�k

Az itt list�zott �lland�kat ez a kiterjeszt�s defini�lja, �s csak akkor el�rhet�ek, ha az adott kiterjeszt�s be van ford�tva a PHP-be, vagy dinamikusan bet�lt�tt.

MSSQL_ASSOC (integer)

MSSQL_NUM (integer)

MSSQL_BOTH (integer)

SQLTEXT (integer)

SQLVARCHAR (integer)

SQLCHAR (integer)

SQLINT1 (integer)

SQLINT2 (integer)

SQLINT4 (integer)

SQLBIT (integer)

SQLFLT8 (integer)

Tartalom
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
[email protected]
11-Feb-2000 10: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.
[email protected]
21-Apr-2000 04: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
[email protected]
07-Jul-2000 05: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!

[email protected]
24-Dec-2000 10: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.

[email protected]
22-Feb-2001 01: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

[email protected]
22-Feb-2001 08: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.

[email protected]
19-Apr-2001 04:01

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

[email protected]
13-Jun-2001 05: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 12: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)

[email protected]
31-Jan-2002 10:19

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

visit my Site:

[email protected]
11-Feb-2002 06: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");
?>

[email protected]
21-Feb-2002 07: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 !!!!

[email protected]
15-Apr-2002 05: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

[email protected]
24-Apr-2002 09: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

[email protected]
05-Jul-2002 05: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

[email protected]
10-Jul-2002 07:18

> "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"

as you can see, the php_mssql.dll and PHP itself have different versions. Maybe there is an old php_mssql.dll lying around in \windows\system(32) or so...

[email protected]
23-Jul-2002 09:30

I'm really lost trying to do ANYTHING with php-mssql integration. If anyone can help me out with some tutorials on how to do simple things, like query a mssql database and add data, retrieve data, etc, it would be most appreciated.

JD

[email protected]
04-Aug-2002 05:48

I have a same problem in MSWINDOWS 2000 and apache 1.3.24
if i enable the extension=php_mssql.dll the i receive an error message

messagebox title - "php.exe - Entry Point Not Found"
Error message "The procedure entry point _ecalloc could not be located in the dynamic link library php4ts.dll

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()"

And if i disable extension=php_mssql.dll then i get in browser
"Fatal error: Call to undefined function: mssql_connect()"

i Please guide me with a solution
Ganesh

[email protected]
05-Aug-2002 05:11

Hello!

Just a Hint:
You have to install the Connectivity-Part from the SQl-Server CD or the MSDE to use the php_mssql.dll.

[email protected]
16-Aug-2002 12:58

We observed that datetime values returned through the mssql functions were in a different format to that observed in Enterprise Manager / Query Analyzer.

i.e. EM said: 2002-08-16 09:58:06
PHP-MSSQL said: 16 Aug 2002 9:58

The following php.ini setting stopped this from happening:

mssql.datetimeconvert = Off

System: PHP 4.2.2, SQL Server 2000, Win 2000 Server

[email protected]
28-Aug-2002 09:38

If you are running IIS/MSSQL/PHP with PHP in CGI mode and are getting a "CGI Error" message from IIS, read on...

A bug exists in the MSSQL driver (possibly on Microsoft's side) that will cause this problem on high performance servers running PHP in CGI mode, especially if your app uses frames. It is related to lots of simultaneous connections to the SQL server from PHP.

A bugnote on the PHP database had lots of input, which can be read here:


A solution was found, which involves tuning the Win2k or WinXP server for 'Forground Applications'. This eliminates the problem completely.

It seems that CGI applications under IIS are launched into user space, owned by the IUSR_* user. So tuning the server to process forground apps makes sense.

To do this, right-click 'My Computer', select 'Properties', select the 'Performance' tab, and then select 'Forground Applications' and click 'OK'.

add a note about notes
previousmime_content_typemssql_bindnext
Last updated: Fri, 30 Aug 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Wed Sep 4 00:18:56 2002 CEST