MySQL::TruncateTable PHP Method

TruncateTable() public method

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
    public function TruncateTable($tableName)
    {
        $this->ResetError();
        if (!$this->IsConnected()) {
            $this->SetError("No connection");
            return false;
        } else {
            $sql = "TRUNCATE TABLE `" . $tableName . "`";
            if (!$this->Query($sql)) {
                return false;
            } else {
                return true;
            }
        }
    }

Usage Example

Esempio n. 1
0
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
}
All Usage Examples Of MySQL::TruncateTable