LinuxForum.Fans
Тема

CentOS 6.3 + php 5.3 + freetds + MSSQL 2008

Автор: XliN 10 сообщений 5355 просмотров
#286544

Есть сервер. Хочется сделать такую связку. Для себя, а то с наскоку попробовал и был удивлен. Все не так просто как хотелось бы.

На сервере поставил

text
freetds-0.91-2.el6.i686
freetds-devel-0.91-2.el6.i686
unixODBC-2.2.14-11.el6.i686
unixODBC-devel-2.2.14-11.el6.i686
perl-DBD-ODBC-1.23-1.el6.rf.i686

Показываю конфиги

text
 cat /etc/freetds.conf
#   $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database # server specific section [global] # TDS protocol version tds version = 8.0

# Whether to write a TDSDUMP file for diagnostic purposes # (setting this to /tmp is insecure on a multi-user system) dump file = /tmp/freetds.log ; debug flags = 0xffff

# Command and connection timeouts ; timeout = 10 connect timeout = 10

# If you get out-of-memory errors, it may mean that your client # is trying to allocate a huge buffer for a TEXT field. # Try setting 'text size' to a more reasonable limit text size = 64512

# A typical Sybase server #egServer50] # host = symachine.domain.com # port = 5000 # tds version = 5.0 # # A typical Microsoft server [mssql] server = 192.168.2.100 port = 1433 tds version = 8.0

[console]cat /etc/odbc.ini[/console]

text

[Intranet]
Driver          = Intranet
Port            = 1433
Description     = ODBC connection via FreeTDS
Servername      = Intranet
ServerNode      = 192.168.2.100
Database        = test-base

[console] cat /etc/odbcinst.ini[/console]

text

[ODBC]
Trace           = Yes
TraceFile       = /tmp/sql.log
ForceTrace      = Yes
Pooling         = No

[Intranet] Description = FreeTDS Driver = /usr/lib/libtdsodbc.so.0 FileUsage = 1 CPTimeout = 5 CPReuse = 5 UsageCount = 1

[console]/usr/bin/tsql -S 192.168.2.100 -U sa Password:
locale is "ru_RU.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20009 (severity 9):
Unable to connect: Adaptive Server is unavailable or does not exist
OS error 111, "В соединении отказано"
There was a problem connecting to the server[/console]
[console] isql -v Intranet sa
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect
[/console]

Собираем информацию

text
 tsql -LH 192.168.2.100
     ServerName SERVER
   InstanceName SQLEXPRESS
    IsClustered No
        Version 10.50.1600.1
            tcp 1700
text
 tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v0.91
             freetds.conf directory: /etc
     MS db-lib source compatibility: yes
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 4.2
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: yes
#286545
text
[root@domain ~]# php -v
PHP 5.3.3 (cli) (built: Jul  3 2012 16:40:30)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
[root@domain ~]# php -m | grep mss
mssql
#286550

Как всегда сам с собой. Разобрался. Теперь нужен пример на php, что бы проверить коннект.

#286553
XliN написал:
Как всегда сам с собой. Разобрался. Теперь нужен пример на php, что бы проверить коннект.
text
<?php
phpinfo();
?>
#286554
"XliN" написал:
Как всегда сам с собой.

Просто freetds + MSSQL спецефично.

#286555

Вот этим можно проверить.

Показать
text

<?php
// Server in the this format: <computer>\<instance name> or 
// <server>,<port> when using a non default port number
$server = 'KALLESPC\SQLEXPRESS';

// Connect to MSSQL $link = mssql_connect($server, 'sa', 'phpfi');

if (!$link) { die('Something went wrong while connecting to MSSQL'); } ?>

#286556
karl_muenhgausen написал:
[quote=XliN]Как всегда сам с собой. Разобрался. Теперь нужен пример на php, что бы проверить коннект.
text
<?php
phpinfo();
?>

[/quote]
С этим не было проблем с самого начала. Ставится php-mssql и модуль подцепляется. Проблема в связке freetds и odbc. Еще проблемы были с путями к либам.

#286558
XliN написал:

С этим не было проблем с самого начала..

Вот всем всегда говорю много лет: хотите учиться на сисадмина вебхостера? Долбайтесь. Хотите учиться вебпрограммированию? Ставьте XAMPP и не сношайте мозг ни себе, ни системе.

#286564
"karl_muenhgausen" написал:
Ставьте XAMPP и не сношайте мозг ни себе, ни системе.

В топку XAMPP.

text
# aptitude install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql

чего блин сложного? сразу работает.
А вот с XAMPP проблемы были, в последнее время меньше, а вот с пол-года год назад - часто. В основном отваливался мускул.

Войдите или зарегистрируйтесь, чтобы ответить.