AV Posted March 22, 2008 Share Posted March 22, 2008 Hello there, this is my code: $dsn = 'mysql://root:@localhost/pred'; $options = array( 'debug' => 2, 'portability' => DB_PORTABILITY_ALL, ); $db =& DB::connect($dsn, $options); if (PEAR::isError($db)) { die($db->getMessage()); } //PREPARE QUERY $sth = $db->prepare("INSERT INTO test SET id=NULL, name='John', surname='Smith' "); if (PEAR::isError($sth)) { die($sth->getMessage()); } $res =& $db->execute($sth, NULL, 'John', 'Smith'); if (PEAR::isError($res)){ die($res->getMessage()); } $db->disconnect(); I written this from manual, and I don't understand one thing. If I have already prepared query, why I have to add data (which I want to put in db) here execute($sth, NULL, 'John', 'Smith')? If I don't put it there, the script will occure an error: DB Error: mismatch. I'd appreciate if somebody could spend some time for me and explain it. Sorry for my english... Quote Link to comment https://forums.phpfreaks.com/topic/97406-pear-need-help/ Share on other sites More sharing options...
Daniel0 Posted March 22, 2008 Share Posted March 22, 2008 When you're preparing a query you're not supposed to include the values. You'll rather put in placeholders which will then later be replaced with the data when you're executing the statement. I.e. $sth = $db->prepare('INSERT INTO test (name, surname) VALUES (?, ?)'); $res = $db->execute('John', 'Smith'); You might want to use PDO instead. It comes with PHP by default and since it's written in C it'll run faster than whatever PEAR library you're using. Quote Link to comment https://forums.phpfreaks.com/topic/97406-pear-need-help/#findComment-498483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.