Truncate Table Before Import (v2021)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
noorshiam
User
Posts: 67
Location: Surabaya - East Java - Indonesia
Contact:

Truncate Table Before Import (v2021)

Post by noorshiam »

Dear All,

I want to make sure my table is really clean before importing data from excel. How do I truncate the table before import from excel.

Thanks for your advice.


arbei
User
Posts: 9367

Post by arbei »

You may use Page_Importing server event to handle the import file first. In v2021, you may get the file path by $options["file"], load it and process it.


noorshiam
User
Posts: 67
Location: Surabaya - East Java - Indonesia
Contact:

Post by noorshiam »

I'm writing this code to Row_Import event :

public function rowImport(&$row, $cnt)
    {
        //Log($cnt); // Import record count
        //var_dump($row); // Import row
        //return false; // Return false to skip import
		$cek = ExecuteScalar("SELECT * FROM wbp WHERE nama = '" .$row["nama"]. "'"); //check if data exist
		if (!empty($cek)) { 
			ExecuteUpdate("DELETE * FROM wbp WHERE nama = '" .$row["nama"]. "'"); //delete data if exist
			return true; //running import
		} else {
			return true; //if not exist, running import
		}

    }

I got error messages --> Server error : 200

But if I refresh page, data successfully imported and List Page show correctly.
Where is the error in writing the code?


arbei
User
Posts: 9367

Post by arbei »

You may read DELETE Statement and check your syntax.


noorshiam
User
Posts: 67
Location: Surabaya - East Java - Indonesia
Contact:

Post by noorshiam »

I change from this :
ExecuteUpdate("DELETE * FROM wbp WHERE nama = '" .$row["nama"]. "'");

to this :
ExecuteUpdate("DELETE FROM wbp WHERE nama = '" .$row["nama"]. "'");

and I still got same error massage : Server error : 200


mobhar
User
Posts: 11709

Post by mobhar »

noorshiam wrote:

$cek = ExecuteScalar("SELECT * FROM wbp WHERE nama = '" .$row["nama"]. "'"); //check if data exist

Double check your code above. If you use ExecuteScalar, then you should SELECT field_name ... and not SELECT * ....

Read Some Global Functions for more info.


noorshiam
User
Posts: 67
Location: Surabaya - East Java - Indonesia
Contact:

Post by noorshiam »

I change my code to:

$cek = ExecuteScalar("SELECT nama FROM wbp WHERE nama = '".$row["nama"]. "'");

And still got same error --> Server error: 200


Post Reply