Topic: bindings not working with xpdo new query  (Read 519 times)

Pages: [1]   Go Down

#1: 16-Dec-2009, 04:33 PM

venu
Posts: 34

hello
i am trying to use xpdo new query function like
$query=$this->mxpdo->newQuery('myclass',array(
  'col1' => $postvars['a'], 
  'col2' => $postvars['b'],
  'col3:LIKE' => '%'.$postvars['c'].'%',
));
$cdata = $this->mxpdo->getCollection('myclass',$query);

but iam always getting error preparing sql statement for query... message

when i debug the query i found the bindings are not assigned to query
like select x from mytable where col1=? and col2=?
any idea why iam getting this error

please help me here

thanks
venu

#2: 16-Dec-2009, 04:39 PM

Foundation

splittingred
Posts: 1,518

i am alt-country rock

WWW
Do you get the same problem if you do:

Code:
$query=$this->mxpdo->newQuery('myclass');
$query->where(array(
  'col1' => $postvars['a'], 
  'col2' => $postvars['b'],
  'col3:LIKE' => '%'.$postvars['c'].'%',
));
$cdata = $this->mxpdo->getCollection('myclass',$query);
shaun mccormick | modx foundation
modx revolution | jira bugtracker | official docs | svn tracker | api docs

#3: 16-Dec-2009, 06:26 PM

venu
Posts: 34

thanks for your reply

yes iam getting the same problem with where clause

first i tried with $query->where(...) but when it dint worked i tied in other way that i mentioned above

but also in xpdocriteria iam getting the same problem

the variables are not binding with sql query

more details about the db
i am using another database in modxrevo
and intialied the xpdo in my class constructor like
$this->mxpdo=new XPDO("mysql:host='localhost';dbname='mydb'", 'test', 'test');
        $this->mxpdo->addPackage('mypackage',$this->config['model_path']);
the package and ORmaps are loading perfectly

not sure whats the mistake here
please help me

thanks

#4: 16-Dec-2009, 07:09 PM

venu
Posts: 34

sorry for wasting your time
found the problem
it is in xpdo instantiation using "" insted of ''
i wrote $mxpdo=new XPDO("mysql:host='localhost';dbname='mydb'", 'test', 'test');
instead of
$mxpdo= new xPDO('mysql:host=localhost;dbname=mydb','test','test','');

but dont find any information about this in debug maps and tables are loading perfectly
so dint expected eroor is in constructor

anyway thanks for your reply

#5: 17-Dec-2009, 12:49 PM

Moderator

OpenGeek
MODx Co-Founder
Posts: 6,977

damn accurate caricatures...

WWW
FYI, this occurred because the actual PDO connection is not made until the first query is executed.
Jason Coward
MODx Co-Founder
xPDO Founder
CTO @ Collabpad
work productively.
work intelligently.
work together.
Light is just a vibration of a note too. Everything is. You've got to keep that in mind.
  Frank Zappa
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.