Wednesday, April 27, 2011

Re: Truncate database table

put this in your app model:

/**
* truncate TABLE (already validated, that table exists)
* @param string table [default:null = current model table]
*/
function truncate($table = null) {
if (empty($table)) {
$table = $this->table;
}
$db = &ConnectionManager::getDataSource($this->useDbConfig);
$res = $db->truncate($table);
return $res;
}


On 27 Apr., 12:07, Tilen Majerle <tilen.maje...@gmail.com> wrote:
> Because, you are calling model's functions not dbo's functions
> try this:
>
> $this->ModelName->query("TRUNCATE TABLE `" . $this->ModelName->useTable .
> "`");
>
> --
> Lep pozdrav, Tilen Majerlehttp://majerle.eu
>
> 2011/4/27 Carachi <carach...@gmail.com>
>
>
>
>
>
>
>
> > Hello,
> > I want truncate a table on mysql so I see that exist a function
> > truncate($table) on dbo_source.php
> > I try to use it so:
>
> >  $this->Model->truncate("Model");  // or  $this->Model->truncate();
>
> >  but it give error like:
>
> > SQL Error: 1064: You have an error in your SQL syntax; check the
> > manual ...
>
> > and the query is:
>
> > Query: truncate
>
> > without the table to truncate.
> > Why?
> > Where I wrong?
>
> > Thank you
> > Bye
>
> > --
> > Our newest site for the community: CakePHP Video Tutorials
> >http://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com For more options, visit this group
> > athttp://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: