使用ODBC连接到数据库会导致警告,并且没有输出任何内容 [英] Connecting to database with ODBC results in warnings and nothing printed

查看:96
本文介绍了使用ODBC连接到数据库会导致警告,并且没有输出任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将ODBC与php一起使用,但似乎出现了一些问题.这是我的代码:

I am trying to use ODBC with php and I seem to be having some problems. This is my code:

<?php
    $connect = odbc_connect("digitallibrary", "root", "");
    $sql = "SELECT name FROM books";
    $result = odbc_exec($connect, $sql);
    echo $result;

    while (odbc_fetch_row($result)) {
        $name = odbc_result($result, "name");
        print("$name\n");
    }
    odbc_close($connect);
    ?>

我还安装了mysql odbc连接器,并添加了此系统DSN: 数据源名称:数字图书馆 TCP/IP服务器:本地主机端口80 用户:root 数据库:数字图书馆

I have also installed mysql odbc connector and added this system DSN: Datasource Name : digitallibrary TCP/IP Server: localhost Port 80 user: root database:digitallibrary

运行代码时,我收到此警告,但未打印任何内容:

When I run my code I get this warnings but nothing printed:

警告:odbc_connect():SQL错误:[Microsoft] [ODBC驱动程序管理器]指定的DSN包含驱动程序和应用程序之间的体系结构不匹配,SQLConnect中SQL状态IM014在E:\ Program Files \ xampp \ htdocs \ DigitalLibrary中\ index.php,第9行

Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application, SQL state IM014 in SQLConnect in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 9

警告:odbc_exec()期望参数1为资源,给定布尔值 在第11行的E:\ Program Files \ xampp \ htdocs \ DigitalLibrary \ index.php中

Warning: odbc_exec() expects parameter 1 to be resource, boolean given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 11

警告:odbc_fetch_row()期望参数1为资源,为null 在E:\ Program Files \ xampp \ htdocs \ DigitalLibrary \ index.php中给出 第14行

Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 14

警告:odbc_close()期望参数1为资源,布尔值 在E:\ Program Files \ xampp \ htdocs \ DigitalLibrary \ index.php中给出 第18行

Warning: odbc_close() expects parameter 1 to be resource, boolean given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 18

我在做什么错了?

推荐答案

现在,您正在尝试将64位应用程序与32位ODBC驱动程序一起使用,反之亦然.您应该检查您使用的是64位还是32位PHP应用.之后,您必须启动正确的ODBC管理员.有32 bit64 bit两种类型.

Now, You are attempting to use a 64 bit application with a 32 bit ODBC driver or vice versa. You should check that what are you using the PHP application 64 bit or 32 bit. After that you have to start the correct ODBC administrator. There are 2 types which are 32 bit and and 64 bit.

如果您使用的是64位ODBC管理员:位于管理工具的控制面板中

If you are using 64 bit ODBC administrator: It is in Adminstrative tools, control panel

如果您使用的是32位ODBC管理员:您应该进入路径%windir\syswow64\odbcad32.exe.

If you are using 32 bit ODBC administrator: You should go into the path %windir\syswow64\odbcad32.exe.

设置正确的ODBC管理员后.您还需要创建系统DSN.如果您在管理员中找不到MS Access驱动程序,则需要为该体系结构下载一个.

When you have set the right ODBC administrator. You will also need to create the system DSN. If you cannot find the MS Access driver in the administrator you'll need to download one for that architecture.

编辑:您可以从此处下载32位

EDIT : you can download the 32 bit from here

希望这会有所帮助.

这篇关于使用ODBC连接到数据库会导致警告,并且没有输出任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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