访问Access Transfer

时间:2011-03-21 22:56:34

标签: php ms-access com adodb

我已经在这里匆匆问了几个问题,我无处可去,我不断改变事情,最后遇到了一个不同的问题,并且没有找到导致它的原因。我是一个PHP MYSQL人,我不得不通过COM类使用Access。

基本上,客户端有多个服务器,每个服务器都有一个访问数据库,每个服务器都有一个CMS,这些表应该包含相同的数据并且已经没有同步。我的工作是想出一种重新同化它们的方法。

我已经将数据输出到一个数组中,将其序列化并保存到主服务器上的文件(所有应该同步到的文件),然后在其他服务器上,下载文件,反序列化它和项目按项目,检查它是否在数据库中,如果没有插入它。插入失败。我已经尝试为每个项目构建一个sql查询并执行$ this-> conn-> Execute();那是在愚蠢的事情上一行一步地失败,所以我现在正在尝试这个:

function syncCMS()
    {
       $this->output['msg'] .= "<p><b>The following properties were added to the database on ." . $this->hsite . "</b></p>";
       $this->get_field_names();
       $this->make_connection(); //assigns connection to $this->conn
        $rs = new COM('ADODB.Recordset');
        $rs->CursorType = 2;
        $rs->CursorLocation = 1;
        $rs->LockType = 4;
        $rs->Open($this->table_name,$this->conn);
        foreach ($this->awayPropertyDetails as $key => $property)
        {
            $this->check_for_property($property['pname']);
            if (!$this->property_exists || $this->mode == "fullSync")
            {
               unset($values);
               $bfields = array("pshow","rent","best", "oda1",  "oda2", "oda3", "oda4", "oda5", "oda6", "odap", "topool","tomountain","tofitness","tosauna"); //stores the yes/no values
               $q = "INSERT INTO " . $this->table_name . " (" . $this->dbfields . ") VALUES (";
                foreach ($property as $k => $value)
                {

                    if ($k == "Kimlik") {
                        $value = null;
                    }
                    if ($k == "tarih")
                    {
                        $value = date("d/m/Y");
                        $value = "'" . $value . "'";
                    }
        if (in_array($k,$bfields))
                {
                   if ($value == "")
                   {
                       $value = 'FALSE';
                   }
                   else 
                   {
                       $value = 'TRUE';
                   }
                }
                     $rs->fields->$k = $value;
$this->output['msg'] .= $property['pname'] . " added";
                }

        $rs->BatchUpdate();
                $rs->Close();
                $this->conn->Close();
               //$this->download_images($property['OBJECT_NR'],$k);
                //$this->output['msg'] .= "<p>Images added</p>";

            }


       }
$message .= "</ul>";
$this->output['msg'] .= $message;
        $this->sendOutput();
        //print_r($property);*/
    }

得到这个:

致命错误:未捕获的异常'com_exception',消息'无法查找`Kimlik':未知名称。 '在D:\ inetpub ......

Kimlik是第一个字段的名称,自动编号字段,我把它拿出来,问题转移到了第二个字段。

1 个答案:

答案 0 :(得分:0)

我到了那里:

$sql = "SELECT * FROM " . $this->table_name;
if (!$this->property_exists || $this->mode == "fullSync")
            {
               $this->make_connection();
               $rs->Open($sql,$this->conn);
              $rs->addnew();
               foreach($rs->Fields as $field)
               {
                   if ($field->name != "Kimlik")
                   {
                   $rs->Fields[$field->name] = $property[$field->name];
                   }
               }

              $rs->Update();
              $rs->Close();
              $this->conn->Close();

               $msg = $this->download_images($property['OBJECT_NR'],$k);
               $this->output['msg'] .= $property['pname'] . " added<br/>" . $msg . "<br/><br/>";

            }