PDO_DBLIB DSN

(PECL PDO_DBLIB >= 0.9.0)

PDO_DBLIB DSNMicrosoft SQL Sunucusu ve Sybase veritabanlarına bağlantı

Açıklama

PDO_DBLIB DSN'si şu bileşenlerden oluşur:

DSN öneki

DSN öneki, PDO_DBLIB, Sybase ct-lib kütüphaneleri kullanılmak üzere derlenmişse sybase:, Microsoft SQL Sunucusunu kullanmak üzere derlenmişse mssql:, FreeTDS kütüphanelerini kullanmak üzere derlenmişse dblib: dizgesidir.

host

Veritabanını barındıran konağın adı veya IP adresi; 127.0.0.1 öntanımlıdır.

dbname

Veritabanının ismi.

charset

İstemcinin karakter kümesi.

appname

Uygulama ismi (sistem süreçlerinde kullanılır). "PHP Generic DB-lib" veya "PHP freetds" öntanımlıdır.

secure

Şimdilik kullanılmamaktadır.

Örnekler

Örnek 1 - PDO_DBLIB DSN örnekleri

Aşağıdaki örnekte, Microsoft SQL Sunucusu ve Sybase veritabanlarına bağlanmak için kullanılan PDO_DBLIB DSN'leri gösterilmiştir:

mssql:host=localhost;dbname=testdb
sybase:host=localhost;dbname=testdb
dblib:host=localhost;dbname=testdb

add a note

User Contributed Notes 6 notes

up
17
Anonymous
7 years ago
Instead of specifying tds version and client charset in freetds.conf, you may pass it as a parameter.
<?php $dsn = 'dblib:version=7.0;charset=UTF-8;host=domain.example.com;dbname=example;'; ?>
up
9
michal at durys dot pl
9 years ago
If you're using FreeTDS driver and you want to use "charset" parameter then you may have to edit freetds.conf (e.g. /etc/freetds/freetds.conf) and force connection using at least version 7.0 of the protocol.

tds version = 7.0

Charset parameter accepts all encodings supported by iconv (execute iconv --list to show all encodings).
up
3
aero2sing at hotmail dot com
10 years ago
Be careful if you are using dblib with prepared statement, as it will crash if first execution didn't return anything.

referring to https://bugs.php.net/bug.php?id=40639
up
5
slach at 74mail dot ru
14 years ago
when you connect to non standart 1433 port

for win32 use DSN like 'mssql:host=hostname,port;dbname=database'

for FreeTDS and DB-Lib use DSN like  'mssql:host=hostname:port;dbname=database'
up
1
Anonymous
5 years ago
Blank (not null) columns retrieved from SQL Server 2014 were returning a single space.

Setting "tds version = 7.0" in /etc/freetds/freetds.conf fixed the issue.
up
-33
ulisse at atc dot bologna dot it
13 years ago
on Linux ppc64 / PHP 5.1.2 / freetds-0.64 works well this way:

<?php
// ...
$dbh = new PDO("dblib:host=$hostdb;dbname=$dbname", $usr, $psw);
// ...
?>
To Top