Truncates a table removing all data
public TruncateTable ( string $tableName ) : boolean | ||
$tableName | string | The name of the table |
return | boolean | Returns TRUE on success or FALSE on error |
function removewebstock() { echo "Create/clear update DB...\r\n"; $db = new MySQL(true) or die('Cannot connect to MySQL server. Please check settings in mysql.class.php'); $sql = "CREATE TABLE IF NOT EXISTS `import_webstock` (\n `uid` int(11) NOT NULL AUTO_INCREMENT,\n `prodcode` varchar(16) NOT NULL,\n `descr` varchar(254) NOT NULL,\n `category` varchar(254) NULL,\n `url` varchar(254) NULL,\n `price` decimal(10,2) NOT NULL,\n `trade` decimal(10,2) NOT NULL,\n `wholesale` decimal(10,2) NOT NULL,\n `onorder` int(5) NOT NULL DEFAULT '0',\n `stocklevel` decimal(10,0) NOT NULL,\n `updated` date DEFAULT NULL,\n `webready` tinyint(1) NOT NULL DEFAULT '1',\n `supplier` varchar(254) NULL,\n `brand` varchar(254) NOT NULL,\n `model` varchar(254) NOT NULL,\n PRIMARY KEY (`uid`),\n KEY `prodcode` (`prodcode`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; $results = $db->Query($sql); //remove then build table if (!$results) { die('Error contacting database!' . $sql); } $db->TruncateTable("import_webstock"); //destroy table data }
if (isset($argv) && $argv[1] == "cli") { $cli = "1"; } include_once 'mysql.class.php'; include_once 'dbf_class.php'; $db = new MySQL(true) or die('Cannot connect to MySQL server. Please check settings in mysql.class.php'); // Begin a new transaction, but this time, let's check for errors. if (!$db->TransactionBegin()) { $db->Kill(); die('Cannot start DB transactions...quitting now.'); } // We'll create a flag to check for any errors $success = true; global $hkdata; //sql building: BE CAREFUL NOT TO USE semicolon inside the sql!!!! $db->TruncateTable("hkmatrix"); //destroy table data $sql = "CREATE TABLE IF NOT EXISTS `hkmatrix` (\n `uid` int(11) NOT NULL AUTO_INCREMENT,\n `custgroup` varchar(4) NULL,\n `refnum` varchar(10) NULL,\n `prodgroup` varchar(254) NULL,\n `supplier` varchar(254) NULL,\n `prodcode` varchar(16) NULL,\n `matrix` varchar(1) NULL,\n `discount` decimal(10,2) NULL,\n `contract` decimal(10,2) NULL,\n `trade` decimal(10,2) NULL,\n `retail` decimal(10,2) NULL,\n `date_on` date DEFAULT NULL,\n `date_off` date DEFAULT NULL,\n\t`break1` decimal(5,2) NULL,\n\t\n\t`break2` decimal(5,2) NULL,\n\t\n\t`break3` decimal(5,2) NULL,\n\t\n\t`break4` decimal(5,2) NULL,\n\t\n\t`break5` decimal(5,2) NULL,\n\t\n\t`break6` decimal(5,2) NULL,\n\t\n\t`break7` decimal(5,2) NULL,\n\t`price1` decimal(10,2) NULL,`price2` decimal(10,2) NULL,`price3` decimal(10,2) NULL,`price4` decimal(10,2) NULL,`price5` decimal(10,2) NULL,`price6` decimal(10,2) NULL,`price7` decimal(10,2) NULL,\n\t `text` varchar(254) NULL,\n\t `type` varchar(4) NULL,\n PRIMARY KEY (`uid`)\n \n) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; $results = $db->Query($sql); if (!$results) { die('Error contacting database!' . $sql); } // open in read-write mode if (function_exists('dbase_open')) { // only if php was compiled with dbase support $updatemsg .= "Packing database.<br/>"; $dbo = dbase_open('datastore/hkmatrix.dbf', 2); // expunge the database dbase_pack($dbo); } $dbr = new dbf_class('datastore/hkmatrix.dbf');
$db = new MySQL(true) or die('Cannot connect to MySQL server. Please check settings in mysql.class.php'); // Begin a new transaction, but this time, let's check for errors. if (!$db->TransactionBegin()) { $db->Kill(); die('Cannot start DB transactions...quitting now.'); } // We'll create a flag to check for any errors $success = true; //sql building: BE CAREFUL NOT TO USE semicolon inside the sql!!!! $sql = "SELECT MAX(uid) AS uid FROM import_hkstock;"; $result = $db->QuerySingleValue($sql); //get the number of records if (!$result) { die('Error contacting database!' . $sql); } $db->TruncateTable("items"); $db->TruncateTable("categories"); $db->TruncateTable("suppliers"); echo '<body>'; echo '<h1>Web Stock List</h1><br>'; echo 'Yellow= Newly enabled.<br><br>'; echo '<div id="loader">Loading...</div>'; echo '<form method="post">'; echo '<table border=0 width="100%" cellspacing=0>'; echo '<thead> <tr style="background:url(bar2.png) repeat-x;text-align:right" > <th>No. </th> <th>Product code </th> <th>Description </th> <th>URL </th> <th>ChangeDate </th>