gpt4 book ai didi

linux - linux下access数据库的问题

转载 作者:太空宇宙 更新时间:2023-11-04 03:59:07 24 4
gpt4 key购买 nike

我们有一个奇怪的项目,它必须通过 Linux 机器与 MSAccess 数据库交互。

阅读不同的博客后,我们已经能够对现有表进行一些读取,但是,如果我们尝试进行插入或一些特殊查询,则会失败并显示连接已重新启动消息。

我将尝试解释我们所尝试的所有内容。

首先,我们已将系统升级到最新版本的 LAMP,因为 odbc 库似乎存在一些问题。

之后,我们按照此处所述添加了 PDO 连接。https://gist.github.com/amirkdv/9672857

sudo nano/etc/odbcinst.ini

[MDBTools]
Description = MDBTools Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmdbodbc.so.1
Setup = /usr/lib/x86_64-linux-gnu/odbc/libmdbodbc.so.1
FileUsage = 1
UsageCount = 2

之后,我们重新启动了 apache,并且选择查询似乎可以正常工作。

我们使用以下示例并进行一些小的修改。 http://coursesweb.net/php-mysql/pdo-select-query-fetch

我们的数据库有一个表调用测试,其中包含以下信息:

CREATE TABLE `test` (
`Id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50),
`surname` VARCHAR(50),
`count` INTEGER
) ENGINE=myisam DEFAULT CHARSET=utf8;

SET autocommit=1;

INSERT INTO `test` () VALUES (1, 'john', 'smith', 100);
INSERT INTO `test` () VALUES (2, 'Mary', 'simmons', 200);
INSERT INTO `test` () VALUES (3, 'Jane', 'Black', 300);

如果我启动以下 php 文件

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Ejemplo de ODBC</title>

<body>

<?php
$mdb_file="/var/www/Temp/Example.mdb";

$uname = explode(" ",php_uname());
$os = $uname[0];

switch ($os){
case 'Windows':
$driver = '{Microsoft Access Driver (*.mdb)}';
break;
case 'Linux':
$driver = 'MDBTools';
break;
default:
exit("Don't know about this OS");
}

try{
$connect_string = "Driver={$driver};DBQ={$mdb_file};";
$dataSourceName = "odbc:" . $connect_string;
$connection = new PDO($dataSourceName);

$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query = 'SELECT id, name, surname FROM test';
$result = $connection->query($query);

// If the SQL query is succesfully performed ($result not false)
if($result !== false) {
// Parse the result set
foreach($result as $row) {
print_r ("<br>");
print_r ($row);
}
}
$connection = null;

} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
die();
} catch (Exception $e) {
echo "Exception: <br>".$e->getMessage();
die();
}

?>

</body>
</html>

结果我们得到以下行:

Array ( [id] => 1 [0] => 1 [count] => 100 [1] => 100 [name] => john [2] => john [surname] => smith [3] => smith )
Array ( [id] => 2 [0] => 2 [count] => 200 [1] => 200 [name] => Mary [2] => Mary [surname] => simmons [3] => simmons )
Array ( [id] => 3 [0] => 3 [count] => 300 [1] => 300 [name] => Jane [2] => Jane [surname] => Black [3] => Black )

所以选择似乎有效。

现在,如果我尝试一个简单的插入

$query = 'insert into test (id, count) values (4,400)';
$result = $connection->query($query);

我收到一条重置连接的消息:

La conexión al servidor fue reiniciada mientras la página se cargaba.

El sitio podría estar no disponible temporalmente o demasiado ocupado. Vuelva a intentarlo en unos momentos.
Si no puede cargar ninguna página, compruebe la conexión de red de su equipo.
Si su equipo o red están protegidos por un cortafuegos o proxy, asegúrese de que Firefox tiene permiso para acceder a la web.

所以我在 php 上添加了调试

http:  //jrs-s.net/2012/05/24/enabling-core-dumps-on-apache2-2-on-debian/

sudo apt-get install apache2-dbg libapr1-dbg libaprutil1-dbg

sudo nano /etc/apache2/apache2.conf
CoreDumpDirectory /tmp/apache2-dumps

mkdir /tmp/apache2-dumps ;
chmod 777 /tmp/apache2-dumps

sudo /etc/init.d/apache2 restart

启动我的 php 文件后,我看到转储文件夹上有一个新的核心文件。

所以我执行 sudo gdb apache2/tmp/apache2-dumps/core

当我收到(gdb)提示时,我执行“bt”命令并获取以下信息:

#0  0x00007ff38c49c3b1 in vfprintf () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ff38c55a344 in __vsprintf_chk () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ff37cbf538f in mdb_sql_error () from /usr/lib/x86_64-linux-gnu/libmdbsql.so.2
#3 0x00007ff37cbf6cbb in ?? () from /usr/lib/x86_64-linux-gnu/libmdbsql.so.2
#4 0x00007ff37cbf6691 in mdb_sql_run_query () from /usr/lib/x86_64-linux-gnu/libmdbsql.so.2
#5 0x00007ff37d012640 in ?? () from /usr/lib/x86_64-linux-gnu/odbc/libmdbodbc.so.1
#6 0x00007ff37c4e3c4a in ?? () from /usr/lib/x86_64-linux-gnu/libodbccr.so.1
#7 0x00007ff37ecc3d70 in SQLExecute () from /usr/lib/x86_64-linux-gnu/libodbc.so.1
#8 0x00007ff37e69923c in odbc_stmt_execute (stmt=0x7ff38d203338) at /build/buildd/php5-5.5.12+dfsg/ext/pdo_odbc/odbc_stmt.c:173
#9 0x00007ff3861ff59c in zim_PDO_query (ht=1, return_value=0x7ff38d203280, return_value_ptr=0x0, this_ptr=0x7ff38d202dd0, return_value_used=1) at /build/buildd/php5-5.5.12+dfsg/ext/pdo/pdo_dbh.c:1134
#10 0x00007ff389201819 in dtrace_execute_internal (execute_data_ptr=<optimized out>, fci=<optimized out>, return_value_used=<optimized out>) at /build/buildd/php5-5.5.12+dfsg/Zend/zend_dtrace.c:97
#11 0x00007ff3892bc15e in zend_do_fcall_common_helper_SPEC (execute_data=0x7ff38d1cf0c0) at /build/buildd/php5-5.5.12+dfsg/Zend/zend_vm_execute.h:552
#12 0x00007ff3892809c8 in execute_ex (execute_data=0x7ff38d1cf0c0) at /build/buildd/php5-5.5.12+dfsg/Zend/zend_vm_execute.h:363
#13 0x00007ff389201706 in dtrace_execute_ex (execute_data=0x7ff38d1cf0c0) at /build/buildd/php5-5.5.12+dfsg/Zend/zend_dtrace.c:73
#14 0x00007ff389213243 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /build/buildd/php5-5.5.12+dfsg/Zend/zend.c:1316
#15 0x00007ff3891b0f1c in php_execute_script (primary_file=0x7fff3030a700) at /build/buildd/php5-5.5.12+dfsg/main/main.c:2506
#16 0x00007ff3892bf6dd in php_handler (r=0x7ff38d15d0a0) at /build/buildd/php5-5.5.12+dfsg/sapi/apache2handler/sapi_apache2.c:667
#17 0x00007ff38d341008 in ap_run_handler (r=0x7ff38d15d0a0) at config.c:170
#18 0x00007ff38d3415fe in ap_invoke_handler (r=0x7ff38d15d0a0) at config.c:439
#19 0x00007ff38d357e3a in ap_process_async_request (r=0x7ff38d15d0a0) at http_request.c:317
#20 0x00007ff38d357f9f in ap_process_request (r=0x7ff38d15d0a0) at http_request.c:363
#21 0x00007ff38d3544a5 in ap_process_http_sync_connection (c=0x7ff38d165290) at http_core.c:190
#22 ap_process_http_connection (c=0x7ff38d165290) at http_core.c:231
#23 0x00007ff38d34ac48 in ap_run_process_connection (c=0x7ff38d165290) at connection.c:41
#24 0x00007ff389b8a633 in child_main (child_num_arg=<optimized out>) at prefork.c:704
#25 0x00007ff389b8a88c in make_child (s=0x7ff38d2adde0, slot=9) at prefork.c:800
#26 0x00007ff389b8b867 in perform_idle_server_maintenance (p=<optimized out>) at prefork.c:902
#27 prefork_run (_pconf=<optimized out>, plog=<optimized out>, s=<optimized out>) at prefork.c:1090
#28 0x00007ff38d325ed6 in ap_run_mpm (pconf=0x7ff38d2db028, plog=0x7ff38d2a9028, s=0x7ff38d2adde0) at mpm_common.c:98
#29 0x00007ff38d31f448 in main (argc=3, argv=0x7fff3030ae18) at main.c:777

但我不知道如何继续。

你能帮我吗?

最佳答案

大卫,嗨

自从我将 Access DB 导入 mysql 以来已经有一段时间了,不幸的是我无法再访问该系统了。但据我记得,我们大多数奇怪的问题都是通过在服务器配置中将语言设置从 utf-8 切换为 iso-8859-1 来解决的。

也许这是一个正确的方向?

关于linux - linux下access数据库的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23605764/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com