I am working on a plugin that needs to run many different queries. I created a class that has many functions and all these functions runs different queries. A DAL basically.
Now when I call these functions in my program, all of them work fine but only one of them runs its query. All other queries in all other function calls don't run.
All the functions run their queries fine if I call only one function in the program.
I cant figure out what the problem is ?
here is some code
THE CONTENTS BELOW HAVE BEEN ADDED LATER
These are the real functions that are giving me trouble.
I call all of them, they all work. But only one of them(the one called last) runs its query. They all run their queries fine if I call only one of them.
class seoklaxxdataAccess{
function addKeyword_start($row_id, $row_keyword, $oldKeyword, $seo_pageContents){
try
{
global $wpdb;
$seo_tblPosts = $wpdb->prefix."posts";
// COMMENT: gets the length of old keyword
$org_keywordLength = strlen($oldKeyword);
$keywordLength = $org_keywordLength+3;
$seo_checkKeyword = substr($seo_pageContents, 0, $org_keywordLength);
if($oldKeyword){
if($seo_checkKeyword==$oldKeyword){
$seo_pageContents = substr($seo_pageContents, $keywordLength);
}
$seo_pageContents = $row_keyword.' - '.$seo_pageContents;
}else{
$seo_pageContents = $row_keyword.' - '.$seo_pageContents;
}
//echo $seo_pageContents."<br>";
$wpdb->update($seo_tblPosts, array('post_content'=>$seo_pageContents), array('ID'=>$row_id));
}
catch(Exception $e)
{
return "not working:".$e->getMessage();
}
}
function addKeyword_end($row_id, $row_keyword, $oldKeyword, $seo_pageContents){
global $wpdb;
$seo_tblPosts = $wpdb->prefix."posts";
// COMMENT: gets the length of old keyword
$org_keywordLength = strlen($oldKeyword);
$keywordLength = $org_keywordLength+3;
$seo_checkKeyword_end = substr($seo_pageContents, -$org_keywordLength);
if($oldKeyword){
if($seo_checkKeyword_end==$oldKeyword){
$seo_pageContents = substr($seo_pageContents,0 , -$keywordLength);
}
$seo_pageContents = $seo_pageContents.' - '.$row_keyword;
}else{
$seo_pageContents = $seo_pageContents.' - '.$row_keyword;
}
$seo_sqlcommand = "UPDATE ".$seo_tblPosts." SET post_content = '".$seo_pageContents."' WHERE ID = '".$row_id."' ;";
//SELECT * FROM wp_seo_keywords WHERE id = ".$row_id.";";
//echo "done".$seo_pageContents."<br>";
$wpdb->get_var($wpdb->prepare($seo_sqlcommand));
}
}
This how I instantiated the class
$seo_dataAccess = new seoklaxxdataAccess();
and this is how I am calling the functions
$seo_dataAccess->addKeyword_start($row_id, $row_keyword, $oldKeyword, $seo_pageContents);
$seo_dataAccess->addKeyword_end($row_id, $row_keyword, $oldKeyword, $seo_pageContents);
$seo_dataAccess->addKeyword_middle_bold_linked($row_id, $row_keyword, $oldKeyword, $seo_pageContents);

$wpdb->prefixfor your table names? – m0r7if3r Feb 28 '12 at 13:04wp_postswould$wpdb->posts... And you should really useprepare()andlike_escape(). Examples can be found in pack of dozens all over the site. Also: Please show your whole class and how you call the class methods. – kaiser Feb 28 '12 at 13:52