duangou1933
duangou1933
2013-08-05 07:34

如何从两个不同的数据库(ms.access和mysql)连接三个表?

  • php
  • mysql
  • pdo

I want to join three tables from two different databases(ms.access and mysql) but i have error

Fatal error: Call to a member function fetch() on a non-object in C:\xampp\htdocs\job\system\hrd\view_absensi.php on line 69

This is my code

<?php include"koneksi.php"; 
 $sql=$dbsql+$dbaccess->query(" attach database dbsql.db as db1
                                attach database dbaccess.db as db2
                                SELECT * p.nip,p.nama,abs.Date_Time
                                FROM 
                                   $db1.HR_Personnel as pabs
                                JOIN $db1.TA_Record_Info AS abs ON abs.Per_ID = pabs.ID
                                JOIN $db2.pegawai_tetap AS p ON p.nip = pabs.Per_Code"); 
        while($p=$sql->fetch(PDO::FETCH_ASSOC)){

and this koneksi.php

    <?php
try{
$dbsql = new PDO('mysql:host=localhost;dbname=dbpenggajian', $user='root', $pass='');
    }
catch(PDOException $e){
    echo $e->getMessage();
    }
try{
    $dbaccess = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\\Kepegawaian Arto Moro\BACK_UP_ABSENSI\TJ_Main_Data.mdb; Uid=userName;Pwd=everyday;");
    }
catch(PDOException $e){
    echo $e->getMessage();
    }

?>

how to solve this problem? thanks for the advice

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答