I am trying to update data using below code but it is generating wrong SQL query. don't understand why it is generating wrong one. Please help me out.
$data = array();
$data['Pers']['etat'] = 1;
$data['Pers']['Activation'] = '';
$this->Pers->id = $results['Pers']['persID'];
$this->Pers->save($data);
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bdr+.pers.persID' in
'where clause'
SQL Query: UPDATE `bdr+`.`pers` SET `etat` = 1, `Activation` = '',
`date_time` = '2014-03-19 11:33:21' WHERE `bdr+.pers.persID` = 37
It means bdr+.pers.persID is generating wrong. Don't understand why it is generating like this.
check if this $results['Pers']['persID'] variable if it is returning a proper format
then try this
$data = array();
$data['Pers']['persID'] = $results['Pers']['persID'];
$data['Pers']['etat'] = 1;
$data['Pers']['Activation'] = '';
//Just to make sure your model is loaded
$this->loadModel('Pers');
if ($this->Pers->save($data, false)) {
echo 'Pres has been saved :) ';
}
Your code containing bdr+.pers.persID` = '37' because $results['Pers']['persID'] supplying 37
Related
Am using a dynamic query to get data. Below is my code
if(objVal != null){
sObject obj = Schema.getGlobalDescribe().get(objVal).newSObject();
if(ConditionVal== null || ConditionVal=='')
query = 'Select Id From '+objVal+ ' Limit 10000';
else{
ConditionVal= String.escapeSingleQuotes(ConditionVal);
query = 'Select Id From '+selectedObj+' WHERE '+ConditionVal+' LIMIT 10000';
}
List<SObject> objlst = Database.query(query);
Am getting "objVal" , "ConditionVal" value form VF page
Example objVal = 'Account' ConditionVal = 'industry = 'Apparel'
after executing the code am getting the query like this
Select Id From Account WHERE industry = \'Apparel\' LIMIT 10000
update the value of ConditionVal variable as below,
ConditionVal = 'Industry = \'Apparel\'';
the query will work as expected.
I have reviewed every post and tried a few recommendations but nothing is working. My code has been fine -- but Gravity Forms did an update and messed up the database tables the data was pulling from so I edited that but the data is still not pulling properly and I am getting the error: Unknown column 'value' in 'where clause' when I turn on debug.
Can anyone see why I am getting this error? The page should be retrieving a list of team members based on the value they have entered in a graavity form field.....all was fine until the update.
Here is the code that is causing the issues - specifically the $get_team_ids and $user_email lines seem to be the offenders.
function showstep1(){
$concate='';
$postid = get_the_ID();
$post_7 = get_post($postid);
if( is_mr() ) {
//print_r($post_7->post_title);
}
//echo $postid;
global $wpdb;
$table_name = $wpdb->prefix . "walking_steps";
$table_name1 = $wpdb->prefix . "users";
$table_name2 = $wpdb->prefix . "gf_entry_meta";
$get_team_ids = $wpdb->get_results("SELECT * FROM $table_name2 where value = '" .$post_7->post_title. "'");
if( is_mr() ) {
//print_r($get_team_ids);
//print_r( $getuserids );
}
$users = array();
if(!empty($get_team_ids)){
foreach ($get_team_ids as $idlead) {
$user_email = $wpdb->get_var("SELECT value FROM wp_gf_entry_meta WHERE form_id=4 AND lead_id=$idlead->lead_id AND field_number=3");
if( empty( $user_email ) ) {
$user_email = $wpdb->get_var("SELECT value FROM wp_gf_entry_meta WHERE form_id=1 AND lead_id=$idlead->lead_id AND field_number=2");
}
if( $user_email ) $users[] = $user_email;
//$concate .= $idlead->lead_id.',';
}
$concate = substr($concate, 0,-1);
//echo $concate;
}
Unknown column 'value' in 'WHERE clause' would usually indicate that the column does not exist in the table.
You say that this is also happening for the other line 'user_email' which also is trying to SELECT the column 'value' again, if this causing you a problem, the column name is not correct it would seem.
Is it the correct header for the column? Seems like an ambiguous name. Try renaming the column 'value' to something less generic or change the where clause to
"WHERE table_name2.value = "
If this is not the column header, please replace 'value' with the correct column header
EDIT: Correct Code below as per comments
Replace all instances of 'value' with 'meta_value'
I have a registration action in Zend controller and I want to ensure that given username isn't already in the database.
$tUser = $userMapper->getDbTable();
$select = $tUser->select()
->from(array('u'=>'users'))
->where('u.user_username = ' . $value);
$row = $tUser->fetchRow($select);
Unfortunately, this snippet of code throws the Exception when i just want to check the $row is null or not and keep writing my code.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'admin' in 'where clause', query was: SELECT u.* FROM users AS u WHERE (u.user_username = admin) LIMIT 1
Should I remove the try/catch blocks in my controller or can I do it in another way?
Judging by error description, I'd say it will throw an exception always, no matter if user exists or not, because bad SQL query will be generated. Try passing $value as second parameter to where, like this:
$tUser = $userMapper->getDbTable();
$select = $tUser->select()
->from(array('u'=>'users'))
->where('u.user_username = ?', $value);
$row = $tUser->fetchRow($select);
You will then check if user exists like this:
if(!$row) {
// user doesn't exist
} else {
// user exists
}
try {
$tUser = $userMapper->getDbTable();
$select = $tUser->select()
->from(array('u'=>'users'))
->where('u.user_username = ?', $value);
$row = $tUser->fetchRow($select);
} catch (Zend_Db_Exception $e) {
echo "<pre>";print_r($e);
}
I want to send 2 strings through array from controller to model and get the results from db, but there is a problem I'm facing.
My controller is like:
$data = array();
if($query = $this->authors_model->get_authors_list(array('author_Type' => array('admin', 'author'))))
{
$data['authors'] = $query;
}
My Model :
function get_authors_list($options = array())
{
if(isset($options['author_Type']))
$this->db->where('author_Type', $options['author_Type']);
$this->db->order_by('author_Id', 'ASC');
$query = $this->db->get('mg_authors');
return $query->result();
}
and the error I'm getting:
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: database/DB_active_rec.php
Line Number: 427
Error Number: 1054
Unknown column 'Array' in 'where clause'
SELECT * FROM (mg_authors) WHERE author_Type = Array ORDER BY
author_Id ASC LIMIT 15
Filename: D:\xampp\htdocs\sport\system\database\DB_driver.php
Line Number: 330
You need to use WHERE IN when you put array. In CodeIgniter, it need to do like this:
$this->db->where_in('author_Type', $options['author_Type']);
The following select returns an empty result set, although it shoudn't:
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_xmluploader_xml_import_tree', 'xml_import_id='.$xml_import_id);
$xml_import_id is set. And it works if I remove the where clause..
Thanks
I still don't understand why it doesn't work.. A simple workaround suggested by a coleague:
// select all from the db
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_xmluploader_xml_import_tree');
while( $entry = $GLOBALS['TYPO3_DB']->sql_fetch_assoc() )
{
if( $entry['xml_import_id'] == $xml_import_id ) {
....
}
}
First, make sure the following is set in localconf.php:
$TYPO3_CONF_VARS['SYS']['sqlDebug'] = '1';
$TYPO3_CONF_VARS['FE']['debug'] = '1';
Then try
$res = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_xmluploader_xml_import_tree', 'xml_import_id='.$xml_import_id);
t3lib_div::debug($res);
Result is the output of the query in the frontend. You can then execute it in MySQL for debugging.
a) make sure $xml_import_id actually has a value (one which is in the database as well)
b) Try this:
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
'tx_xmluploader_xml_import_tree',
"xml_import_id='".$xml_import_id."'"
);
How do you process the result?
How does your expected $xml_import_id value look like?
cu
Roman