无法在Ubuntu 14.04上为php5.6安装sqlsrv库

时间:2018-07-20 15:05:52

标签: php sql-server odbc ubuntu-14.04 unixodbc

如何安装该库以使用php5.6连接到mssql 2012?

更新:  我发现版本3.0.1是正确的版本(如果我输入错了,请纠正我)。

但是现在,我收到此错误:

class ModificationInformation(EmbeddedDocument):
    user = ObjectIdField()
    date = DateTimeField(default=datetime.datetime.utcnow)

class User(Document):
    username = StringField()
    first_name = StringField()
    last_name = StringField()
    date_created = EmbeddedDocumentField(ModificationInformation)
    date_modified = EmbeddedDocumentListField(ModificationInformation)

# Create user
user_1 = User(
    username = "jodo",
    first_name = "John",
    last_name = "Doe"        
    )

user_1.save()

user_1.date_created = ModificationInformation(user = user_1.id)
user_1.date_modified = [ModificationInformation(user = user_1.id)]

user_1.save()

更新: 当我尝试手动安装文件时,顶层目录不包含config.m4。它只包含config.w32 ...我该怎么办?

2 个答案:

答案 0 :(得分:0)

您可以安装以下特定版本:pecl install sqlsrv-4.3.0

您必须浏览变更日志here来找到所需的版本。

答案 1 :(得分:0)

在CentOS 7上遇到相同的问题。pecl.php.net中的档案(版本3.0.1,在4.0.4文件中,但最低要求php7.0)不存在文件config.m4。我认为该模块不适用于linux php 5版本。最好编译mssql模块。

这就是为什么我从https://museum.php.net下载完整的php归档文件(在我的情况下是-php-5.6.40.tar.xz)并从中编译mssql

cd /tmp/
wget https://museum.php.net/php5/php-5.6.40.tar.gz
tar xvf php-5.6.40.tar.gz
cd php-5.6.40/ext/mssql/
/opt/php56/bin/phpize (in your case path to php5.6 phpize can be different)
yum install autoconf (on ubuntu package can have different name)
yum install freetds freetds-devel freetds-libs freetds (required to compile)
ln -s /usr/lib64/libsybdb.so /usr/lib/libsybdb.so (compiling search for libsybdb.so in /usr/lib/libsybdb.so but file was in  /usr/lib64/libsybdb.so that why i create symlink)
./configure --with-php-config=/opt/php56/bin/php-config (in your case path to php5.6 php-config can be different)
make

我用我的php5.6配置得到mssql模块

/tmp/php-5.6.40/ext/mssql/modules/mssql.so

并且可以轻松地将其连接到php.ini中的php56