Merhaba, Ziyaretçi. Lütfen giriş yapın veya üye olun.
Aktivasyon mailiniz gelmediyse buraya tıklayın.
Mayıs 13, 2008, 10:32:11 am
41808 Mesaj 9080 Konu Gönderen: 17476 Üye
Son üye: cakcan
Turk-Php.Com Forum  |  Yardım Forumları  |  PHP Yardım Forumu  |  PHP Class Deposu  |  MS ACCESS TEN veri okuyan Class « önceki sonraki »
Sayfa: [1] Yazdır
Yazan Konu: MS ACCESS TEN veri okuyan Class  (Okunma Sayısı 836 defa)
phparmy
phparmy
PHP Stajyeri
**
Offline Offline

Mesaj Sayısı: 346


Elektronik imzam.


Üyelik Bilgileri
MS ACCESS TEN veri okuyan Class
« : Ekim 06, 2006, 04:08:00 am »

Class dosyası
Kod:
<?php
class mdb
{
  var 
$RS 0;
  var 
$ADODB 0;
  
  var 
$RecordsAffected;
  
  var 
$strProvider 'Provider=Microsoft.Jet.OLEDB.4.0';
  var 
$strMode     'Mode=ReadWrite';
  var 
$strPSI      'Persist Security Info=False';
  var 
$strDataSource  '';
  var 
$strConn     '';
  var 
$strRealPath '';
  
  var 
$recordcount 0;
  var 
$ok false;
  
  
  
/**
  * Constructor needs path to .mdb file
  *
  * @param string $dsn = path to *.mdb file
  * @return boolean success 
  */
  
function mdb$dsn='Please enter DataSource!' )
  {
    
$this->strRealPath realpath$dsn );
    if( 
strlen$this->strRealPath ) > )
    {
      
$this->strDataSource 'Data Source='.$this->strRealPath;
      
$result true;
    }
    else
    {
      echo 
"<br>mdb::mdb() File not found $dsn<br>";
      
$result false;
    }
    
    
$this->RecordsAffected = new VARIANT();
    
    
$this->open();
    
  } 
// eof constructor mdb()
  
  
  
function open( )
  {
    if( 
strlen$this->strRealPath ) > )
    {
  
      
$this->strConn 
        
$this->strProvider.';'.
        
$this->strDataSource.';'.
        
$this->strMode.';'.
        
$this->strPSI;
        
      
$this->ADODB = new COM'ADODB.Connection' );
      
      if( 
$this->ADODB )
      {
        
$this->ADODB->open$this->strConn );
        
        
$result true;
      }
      else
      {
        echo 
'<br>mdb::open() ERROR with ADODB.Connection<br>'.$this->strConn;
        
$result false;
      }
    }
    
    
$this->ok $result;
    
    return 
$result;
  } 
// eof open()
  
  
  /**
  * Execute SQL-Statement
  * @param string $strSQL = sql statement
  * @param boolean $getrecordcount = true when a record count is wanted
  */
  
function execute$strSQL$getrecordcount false )
  {

    
$this->RS $this->ADODB->execute$strSQL, &$this->RecordsAffected );
    
    if( 
$getrecordcount == true )
    {

      
$this->RS->MoveFirst();
      
$this->recordcount 0;
      
      
# brute force loop
      
while( $this->RS->EOF == false )
      {
        
$this->recordcount++;
        
$this->RS->MoveNext();
      }
      
$this->RS->MoveFirst();

    }
    
        
  } 
// eof execute()
  
  
function eof()
  {
    return 
$this->RS->EOF;
  } 
// eof eof()
  
  
function movenext( )
  {
    
$this->RS->MoveNext();
  } 
// eof movenext()
  
  
function movefirst()
  {
    
$this->RS->MoveFirst();
  } 
// eof movefirst()
  
  
function close()
  {
   
    @
$this->RS->Close(); // Generates a warning when without "@"
    
$this->RS=null;
  
    @
$this->ADODB->Close();
    
$this->ADODB=null;
  } 
// eof close()
  
  
function fieldvalue$fieldname )
  {
    return 
$this->RS->Fields[$fieldname]->value;
  } 
// eof fieldvalue()
  
  
function fieldname$fieldnumber )
  {
    return 
$this->RS->Fields[$fieldnumber]->name;
  } 
// eof fieldname()
  
  
function fieldcount( )
  {
    return 
$this->RS->Fields->Count;
  } 
// eof fieldcount()  
  
// eoc mdb
?>

Kullanım Şekli
Kod:
<?php
#
# This is some wired example.
# You cannot use it out of the box.
#
# Use your own mdb filename and 
# your own tablename and 
# your own fieldnames.
#
# You really need a Windows Server and a mdb file on it to have it work!
# Big chance it does not work with Linux or Unix - but tell me if it does.
#
# This example opens the mdb once and then reads it twice.
# I know about 2 ways to get the values, so I show them all.
# Maybe there is a speed difference.
#
# Works on a Win 2000 server with PHP 4.3.4 and Microsoft-IIS/5.0
#

include 'class_mdb.php';

$mdb = new mdb('mymdbfile.mdb'); // your own mdb filename required
$mdb->execute('select * from table'); // your own table in the mdb file

#
# first example: using fieldnames


while( !$mdb->eof() )
{
  echo 
$mdb->fieldvalue('description'); // using your own fields name
  
echo ' = ';
  echo 
$mdb->fieldvalue); // using the fields fieldnumber
  
echo '<br>';
  
$mdb->movenext();
}

echo 
'<br><hr><br>';

#
# Going back to the first recordset for the second example
#
$mdb->movefirst();

#
# This works, too: Make each Field an object. The values change
# when the data pointer advances with movenext().

$url $mdb->RS->Fields(1);
$bez $mdb->RS->Fields(2);
$kat $mdb->RS->Fields(3);

while( !
$mdb->eof() )
{
  
# works!
  
echo $bez->value;
  echo 
' = ';
  echo 
$url->value;
  echo 
'<br>';
  
$mdb->movenext(); 
}

$mdb->close(); 

?>

Logged
GaziMarşı
PHP Stajyeri
**
Offline Offline

Mesaj Sayısı: 446


Üyelik Bilgileri
Ynt: MS ACCESS TEN veri okuyan Class
« Yanıtla #1 : Ekim 28, 2006, 06:20:28 pm »

işime çok yarıyacak. tşkler.
Logged

kktcportal
Yeni Kullanıcılar
*
Offline Offline

Mesaj Sayısı: 29


Üyelik Bilgileri
Ynt: MS ACCESS TEN veri okuyan Class
« Yanıtla #2 : Eylül 19, 2007, 03:58:21 am »

Alternatif access'e bağlantı yöntemi
Kod:
$sube = $_POST['sube'];
$conn = new COM("ADODB.Connection") or die("ADODB başlatılamıyor");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:\Database2.mdb");
$rs = $conn->Execute("SELECT * FROM MAASKART where SUBENO like '$sube' ");
echo "<TABLE border='1'><TR><TH colspan='6'>Veriler</TH><TR>";
echo "<TR>";
echo "<TH>" . $rs->Fields[0]->name . "</TH>";
echo "<TH>" . $rs->Fields[1]->name . "</TH>";
echo "<TH>" . $rs->Fields[2]->name . "</TH>";
echo "<TH>" . $rs->Fields[3]->name . "</TH>";
echo "<TH>" . $rs->Fields[4]->name . "</TH>";
echo "<TH>" . $rs->Fields[5]->name . "</TH>";
echo "</TR>";
while (!$rs->EOF)
{
echo "<tr>";
echo "<td>" . $rs->Fields[0]->value . " </td>";
echo "<td>" . $rs->Fields[1]->value . " </td>";
echo "<td>" . $rs->Fields[2]->value . " </td>";
echo "<td>" . $rs->Fields[3]->value . " </td>";
echo "<td>" . $rs->Fields[4]->value . " </td>";
echo "<td>" . $rs->Fields[5]->value . " </td>";
echo "</tr>";
$rs->MoveNext();
}
echo "</TABLE>";
$rs->Close();
$conn->Close();

$rs = null;
$conn = null;
?>
Logged
Sayfa: [1] Yazdır 
« önceki sonraki »
Gitmek istediğiniz yer: