在Ubuntu中调用未定义的函数odbc_connect() [英] Call to undefined function odbc_connect() in Ubuntu

查看:116
本文介绍了在Ubuntu中调用未定义的函数odbc_connect()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP连接到SQL Server.我已经为SQL Server安装了Microsoft ODBC Driver 13,并且已经使用"isql"命令对其进行了测试.现在,当我尝试使用PHP连接到服务器时,它总是崩溃并显示"http error 500".这是代码:

I am trying to connect with PHP to SQL server. I have installed Microsoft ODBC Driver 13 for SQL Server and I have test it using 'isql' command. Now when I am trying to connect to the server in PHP it always crashes and says "http error 500". Here is the code:

<?php
$server = merkur.edikt.local;
$database = ITServiceE;
$connection = odbc_connect("Driver={ODBC DRIVER 13 for SQL Server};
    Server=$server;Database=$database;", 
    'user', 
    'PW'
);
echo "connected";
?>

我正在使用Ubuntu 16.04服务器以及Apache2和PHP 7. 我认为Apache的权限可能有问题(如果Apache可以访问ODBC驱动程序),但我不确定这是如何工作的. 这是来自Apache错误的日志:

I am using Ubuntu 16.04 server and Apache2 and PHP 7. I think it might be problem with permissions for the Apache(if the Apache can access the ODBC Driver) but I am not really sure how this works. Here is the log from Apache errors:

PHP Notice:  Use of undefined constant merkur - assumed 'merkur' in         /var/www/html/index.php on line 2
PHP Notice:  Use of undefined constant edikt - assumed 'edikt' in /var/www/html/index.php on line 2
PHP Notice:  Use of undefined constant local - assumed 'local' in /var/www/html/index.php on line 2
PHP Notice:  Use of undefined constant ITServiceE - assumed 'ITServiceE' in /var/www/html/index.php on line 3
PHP Fatal error:  Uncaught Error: Call to undefined function odbc_connect() in /var/www/html/index.php:4\nStack trace:\n#0 {main}\n  thrown in /var/www/html/index.php on line 4

,文件odbc.ini为空,odbcinst.ini如下所示:

and the file odbc.ini is empty and odbcinst.ini looks like this:

[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0
Threading=1
UsageCount=2

推荐答案

对未定义函数odbc_connect() 的调用意味着您的PHP系统没有任何具有该名称的函数.

Call to undefined function odbc_connect() means that your PHP system doesn't have any function with that name.

由于它不是用纯PHP编写的用户功能,而是来自PHP扩展的功能,因此,您尚未安装

Since it isn't a user function written in pure PHP but a function from a PHP extension, that means that you haven't installed such extension. It's worth noting that the PHP extensions is not the same as the SQL Server driver (you need both).

您的代码还包含一些未定义的常量,我想它们是字符串.我强烈建议您在开发框中启用完整的错误报告,这样就无需查看错误日志来了解简单错误.

Your code also contains some undefined constants which I guess are meant to be strings. I strongly recommend you enable full error reporting in your development box so you don't need to check the error logs to learn about simple errors.

这篇关于在Ubuntu中调用未定义的函数odbc_connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆