หน้าเว็บ

วันอังคารที่ 28 พฤษภาคม พ.ศ. 2562

PHP : PHP Get Data From Axapta DB

PHP : PHP Get Data From Axapta DB
1. db.php
2. config.php
3. FileGet.php

1. db.php
<?php
class MysqlDB{
var $Host="";
var $User="";
var $Password="";
var $DB="";
var $ShowError="";
var $LinkID="";
var $Result="";
var $NumRows="";
var $NumFields="";

function MysqlDB($Host,$User,$Password,$DB,$ShowError){
    $this->Host=$Host;
    $this->User=$User;
    $this->Password=$Password;
    $this->DB=$DB;
    $this->ShowError=$ShowError;
    if($this->ShowError){
        error_reporting (E_ALL ^ E_NOTICE);
    }else{
        error_reporting (E_ALL ^ (E_NOTICE | E_WARNING));
    }
}

function Connect(){
    if(empty($this->LinkID)){
        $this->LinkID=@mysql_connect($this->Host,$this->User,$this->Password);
//        $this->Result=@mysql_db_query($this->DB,"SET NAMES tis620");
        if(empty($this->LinkID)){
            exit;
        }
    }
}

function Query($Sql){
    $this->Connect();
    @mysql_db_query($this->DB,"SET NAMES tis620");
    $this->Result=@mysql_db_query($this->DB,$Sql);
    $Error=mysql_error();
    if($Error and $this->ShowError){
        echo $Error."<br>".$Sql;
        exit;
    }
    $this->NumRows=mysql_num_rows($this->Result);
    $this->NumFields=mysql_num_fields($this->Result);
    return $this->NumRows;
}

function Update($Sql){
    $this->Connect();
    @mysql_db_query($this->DB,"SET NAMES tis620");
    @mysql_db_query($this->DB,$Sql);
    $Error=mysql_error();
    if($Error and $this->ShowError){
        echo $Error."<br>".$Sql;
        exit;
    }
}

function GetRow(){
    return mysql_fetch_array($this->Result);
}

function DataSeek($i){
    return mysql_data_seek($this->Result,$i);
}

function GetObject(){
    return mysql_fetch_object($this->Result);
}

function LastID(){
    return mysql_insert_id($this->LinkID);
}

function FieldName($FieldNumber){
    return mysql_field_name($this->Result,$FieldNumber);
}

}
?>

2. config.php
<?php
//MS SQL Config.
$MSServer = "xxxxx";
$MSUser = "xxx";
$MSPass = "xxxx";
$MSDB = "xxxxx";

//connection to the database
$dbhandle = mssql_connect($MSServer, $MSUser, $MSPass)
  or die("Couldn't connect to SQL Server on $MSServer");

//select a database to work with
$selected = mssql_select_db($MSDB, $dbhandle)
  or die("Couldn't open database ".$MSDB);
 
//MySQL Config. 
$Host="localhost";
$User="xxxxx";
$Password="xxxxx";
$DB="xxxx";
$ShowError=0;

?>
3. FileGet.php
<?php
    include_once("config.php");
    include_once("db.php");
   
    $myDB    = new MysqlDB($Host,$User,$Password,$DB,$ShowError);
    echo "Update Data From Axapta To Phpmyadmin.";

    //echo "<td align='center'>Update Data From Axapta To Phpmyadmin.</td>";

    $query  = "SELECT RefRecId, CONVERT(VARCHAR(10), TransDate, 120) AS TransDate, JournalId, CostAmount, AccountNum, AccountName, Department, Txt, CheckType";
    $query .= " FROM SCI_TmpMIToPhp ";
    //$query .= " WHERE purchLine.RecId = '".$RecId."' ";
    $result = mssql_query($query) or die("Couldn't query");
    $mssqlRows = mssql_num_rows($result);
    if($mssqlRows > 0){
        $row = mssql_fetch_array($result);
    }
    //mssql_free_result($result);
    //echo $row["JournalId"];
   
    //Loop display the results
    while($row = mssql_fetch_array($result))
    {
          //echo "<li>" . $row["JournalId"] . " : ". $row["TransDate"] ." : ". $row["Department"] ." : ". $row["ItemId"] ."</li>" ;
          //$TransDate = date_format($row["TransDate"], "Y-m-d");
          //$SQL .= " WHERE ( AccountNum = '1111000' OR AccountNum = '1111001' OR AccountNum = '1111200' OR AccountNum = '1111500')";
          $AccountNum = $row["AccountNum"];
          $Txt = $row["Txt"];
        if($AccountNum == 1111000 || $AccountNum == 1111001 || $AccountNum == 1111200 || $AccountNum == 11111500){
            $ItemId = substr($Txt, 0, 12);
            $LenTxt = strlen($Txt);
            $Txt = substr($Txt, 15, $LenTxt);          
        } else {
            $ItemId = "";
        }        
        
       $SQL = " INSERT INTO sci_consume_chart.Data (RefRecId, TransDate , JournalId, AccountNum, AccountName, ItemId, Txt, Amount, Department, CheckType)";
        $SQL.= " VALUES ('".$row["RefRecId"]."', '".$row["TransDate"]."', '".$row["JournalId"]."', '".$AccountNum."','".$row["AccountName"]."','".$ItemId."','".$Txt."','".$row["CostAmount"]."','".$row["Department"]."','".$row["CheckType"]."')";          
        //echo $SQL;
        $myDB->Update($SQL);
    }

    echo "<br><br><font color='green'> Update Data Finish. Please Close This Page.</font>";
?>

ไม่มีความคิดเห็น:

แสดงความคิดเห็น