PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<mime_content_typemssql_bind>
view the version of this page
Last updated: Sun, 02 May 2004

LIX. Funzioni per Microsoft SQL Server

Introduzione

Queste funzioni permettono di accedere ad un database MS SQL Server.

Requisiti

Requisiti per le piattaforme Win32

Per potere funzionare è richiesto che sia installato il MS SQL Client Tools sullo stesso sistema su cui è il installato il PHP. Il Client Tools può essere installato o dal cd di MS SQL Server, o copiando il file ntwdblib.dll dalla directory \winnt\system32 del server alla directory \winnt\system32 della macchina su cui è installato il PHP. La copia del file ntwdblib.dll permette solo l'accesso al database. La configurazione del client richiede comunque l'installazione di tutto il pacchetto MS SQL Client Tools.

Requisiti per le piattaforme Unix/Linux

Per potere utilizzare l'estensione MSSQl su piattaforme Unix/Linux, occorre compilare ed installare la libreria FreeTDS. Il codice sorgente e le istruzioni per l'installazione sono disponibili nel sito di FreeTDS: http://www.freetds.org/

Nota: Nella piattaforma Windows si utilizzano le DBLIB di Microsoft. Quindi le funzioni che restituiscono il nome della colonna si basano sulla funzione dbcolname() della DBLIB. La DBLIB è stata sviluppata per SQL Server 6.x che ammetteva nomi di colonna lunghi al massimo 30 caratteri. Per questo motivo il numero massimo di caratteri per il nome colonna ammessi sono 30. Nelle piattaforme in cui si utilizza FreeTDS (Linux) non si ha questo problema.

Installazione

Il modulo MSSQL si abilita aggiungendo extension=php_mssql.dll al file di configurazione php.ini.

Per attivare queste funzionalità occorre compilare il PHP con --with-mssql[=DIR], dove DIR è la directory in cui è installato FreeTDS. Il pacchetto FreeTDS dovrebbe essere compilato utilizzando --enable-msdblib.

Configurazione di Runtime

Il comportamento di queste funzioni è influenzato dalle impostazioni di php.ini.

Tabella 1. Parametri di configurazione per il modulo MS SQL Server

NomeDefaultModificabile
mssql.allow_persistent"1"PHP_INI_SYSTEM
mssql.max_persistent"-1"PHP_INI_SYSTEM
mssql.max_links"-1"PHP_INI_SYSTEM
mssql.min_error_severity"10"PHP_INI_ALL
mssql.min_message_severity"10"PHP_INI_ALL
mssql.compatability_mode"0"PHP_INI_ALL
mssql.connect_timeout"5"PHP_INI_ALL
mssql.timeout"60"PHP_INI_ALL
mssql.textsize"-1"PHP_INI_ALL
mssql.textlimit"-1"PHP_INI_ALL
mssql.batchsize"0"PHP_INI_ALL
mssql.datetimeconvert"1"PHP_INI_ALL
mssql.secure_connection"0"PHP_INI_SYSTEM
mssql.max_procs"25"PHP_INI_ALL
Per maggiori dettagli sulle costanti PHP_INI_* vedere ini_set().

Tipi di risorse

Costanti predefinite

Queste costanti sono definite da questa estensione e sono disponibili solo se l'estensione è stata compilata nel PHP o se è stata caricata dinamicamente a runtime.

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)

Sommario
mssql_bind --  Aggiunge un parametro ad una procedura memorizzata (stored procedure) locale o remota
mssql_close -- Chiude la connessione con MS SQL Server
mssql_connect -- Apre una connessione con un server MS SQL
mssql_data_seek -- Sposta il puntatore di riga interno
mssql_execute --  Esegue una procedura memorizzata su un database MS SQL
mssql_fetch_array --  Restituisce una riga in un array associativo, numerico o entrambi
mssql_fetch_assoc --  Restituisce un array associativo con i dati di una riga dal set di risultati indicato da id_risultato
mssql_fetch_batch --  Restituisce il successivo gruppo di record
mssql_fetch_field -- Restituisce le informazioni di un campo
mssql_fetch_object -- Restituisce una riga come oggetto
mssql_fetch_row -- Restituisce una riga come array numerato
mssql_field_length -- Restituisce la lunghezza di un campo
mssql_field_name -- Restituisce il nome di un campo
mssql_field_seek -- Ricerca il campo con l'offset specificato
mssql_field_type -- Restituisce il tipo di un campo
mssql_free_result -- Libera la memoria di un risultato
mssql_free_statement -- Free statement memory
mssql_get_last_message --  Restituisce l'ultimo messaggio dal server
mssql_guid_string --  Converte il GUID dal formato binario a 16 bit al formato stringa
mssql_init --  Inizializza una procedura memorizata locale o remota
mssql_min_error_severity -- Setta il livello minimo di errori critici.
mssql_min_message_severity -- Setta li livello critico minimo di messaggi
mssql_next_result -- Muove il puntatore interno al risultato successivo
mssql_num_fields -- Restituisce il numero di campi in un risultato
mssql_num_rows -- Restituisce il numero di righe
mssql_pconnect -- Apre una connessione persistente con MS SQL
mssql_query -- Invia una query a MS SQL
mssql_result -- Restituisce i dati di un risultato
mssql_rows_affected --  Restituisce il numero di record coinvolti dalla query
mssql_select_db -- Seleziona un database MS SQL


add a note add a note User Contributed Notes
Funzioni per Microsoft SQL Server
jasenko at get2net dot dk
05-May-2004 05:46
If you get a crash trying to get currency from database with smallmoney datatype and big value (in my case it was 15000..), change datatype to money instead. The error is gone.

I'm using php 4.2.3 and MSSQL 7.0 on windows.
andrej at dairyweb dot com dot au
28-Apr-2004 07:49
if you are having problems with freeTDS, or like me you are trying to get access to unicode data from mssql.

try http://odbtp.sourceforge.net it is cross platform and (reportedly) faster than freeTDS. it is very stable and easy to configure.

i was originally trying to solve an error message of "Unicode data in Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier" and found this solution.

hope it helps someone.
elmer at web-axis dot net
28-Apr-2004 03:52
Here's something that could save you 2-3 days research trying to figure out:

<?php
putenv
('TDSDUMP=/tmp/tds.log');
putenv('SYBASE=/usr/lib/freetds');
putenv('TDSVER=70');
?>

If you have problems getting the mssql functions to work try these varibles. MSSQL/PHP has problems dealing with different tds versions. 7.0 seems to work well with our server version, maybe a different version would work better with yours.
pmfa at versenet dot com
27-Apr-2004 03:26
If you're going to use freeTDS just to access mssql databases, supply the "--enable-msdblib" switch to the freeTDS configure script when building the library. This will fix some obscure problems, like the month in a date not being displayed correctly, more information in http://www.freetds.org/userguide/config.htm.
gentiboard2002 at yahoo dot de
19-Apr-2004 12:55
there's no documentation of the php.ini option mssql.secure_connection.

so i have here a MS SQL 2000 Server with Windows Authentication and a Windows 2003 Server with IIS 6. So it is clear that i cannot use the usual handling of a mssql_connect.
I turned the mssql.secure_connection on.
I let the Windows IIS to run under an Service Account(normal user account without any special rights) in a Windows Domain, so i do have a authenticated connection to the SQL Server...

Everything works fine without any rewrite of the code...
19-Mar-2004 06:42
Note: DBLib is obsolete and only supports SQL Server 4.x, 6.5, 7.0 and 8.x.
jholland at cs dot selu dot edu
10-Dec-2003 07:37
To enable mssql in php 4.3.3 and above on linux/unix boxes, you must put this line in php.ini

extension=mssql.so

<mime_content_typemssql_bind>
 Last updated: Sun, 02 May 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This mirror generously provided by: Italia OnLine S.p.a.
Last updated: Fri May 21 04:11:23 2004 CEST