PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousmime_content_typemssql_bindnext
Last updated: Tue, 09 Jul 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

LVIII. Microsoft SQL Server

L'extension MSSQL n'est disponible que sous Windows 32 bits. Vous pouvez utiliser l'extension Sybase pour vous connecter � un serveur MSSQL, depuis d'autres plate-formes.

Ces fonctions vous permettent d'acc�der aux serveurs de donn�es MS SQL. Vous avez besoin d'un client MS SQL Client Tools sur votre syst�me, accessible � PHP. Les Client Tools peuvent �tre install� depuis le CD MS SQL Server CD ou en copiant ntwdblib.dll depuis le dossier \winnt\system32 du serveur MS SQL vers \winnt\system32 sur le serveur PHP. Copier ntwdblib.dll ne fera que fournir le moyen d'acc�s. La configuration du client requiert l'installation des autres outils.

L'extension MSSQL est activ�e par la ligne extension=php_mssql.dll dans le fichier php.ini.

Table des mati�res
mssql_bind --  Adds a parameter to a stored procedure or a remote stored procedure
mssql_close -- Ferme une connexion MS SQL Server.
mssql_connect -- Ouvre une connexion � un serveur MS SQL server.
mssql_data_seek -- D�place le pointeur interne de ligne.
mssql_execute --  Executes a stored procedure on a MS SQL server database
mssql_fetch_array -- Lit une ligne dans un tableau.
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 -- Lit les inforamtions sur le champs.
mssql_fetch_object -- Retourne une ligne sous la forme d'un objet.
mssql_fetch_row -- Lit une ligne comme un tableau.
mssql_field_length -- Lit la longueur d'un champs.
mssql_field_name -- Lit le nom d'un champs.
mssql_field_seek -- Fixe l'offset du pointeur de champs.
mssql_field_type -- Lit le nom d'un champs.
mssql_free_result -- Lib�re la m�moire.
mssql_get_last_message --  Retourne le dernier message d'erreur du serveur ( 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 --  Fixe le niveau de s�v�rit� des erreurs.
mssql_min_message_severity --  Fixe le niveau de s�v�rit� des messages d'erreurs.
fbsql_next_result -- D�place le pointeur interne vers le r�sultat suivant
mssql_num_fields -- Retourne le nombre de champs dans un r�sultat.
mssql_num_rows -- Retourne le nombre de lignes dans un r�sultat.
mssql_pconnect --  Ouvre une connexion persistante � un serveur MS SQL.
mssql_query -- Envoie une requ�te SQL.
mssql_result -- Lit les donn�es d'un r�sultat.
mssql_rows_affected --  Returns the number of records affected by the query
mssql_select_db -- S�lectionne la base de donn�es MS SQL.
User Contributed Notes
Microsoft SQL Server
add a note about notes
[email protected]
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.
[email protected]
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
[email protected]
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!

[email protected]
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.

[email protected]
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

[email protected]
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.

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

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

[email protected]
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)

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

[email protected]
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");
?>

[email protected]
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 !!!!

[email protected]
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

[email protected]
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

[email protected]
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

[email protected]
10-Jul-2002 06: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 08: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 04: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 04: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 11: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 08: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: Tue, 09 Jul 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat Aug 31 06:19:44 2002 CEST