问题描述
我正在尝试将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 : digitallibraryTCP/IP Server: localhost Port 80user: rootdatabase:digitallibrary
运行代码时,我收到此警告,但未打印任何内容:
When I run my code I get this warnings but nothing printed:
警告: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 bit
和64 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
.
如果您使用的是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连接到数据库会导致警告,并且没有输出任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!