strangermaster Posted July 21, 2008 Share Posted July 21, 2008 hi i m working on my langmanager class and when i use lang name in statement withount place holders and binding values - it works : good result for "static $findALL = "SELECT stringID, fr FROM langs WHERE pageID='gen'"; " : Array ( [0] => Array ( [stringID] => espacemembres [fr] => Espace membres ) [1] => Array ( [stringID] => accueil [fr] => Accueil ) ) bad result for "static $findALL = "SELECT stringID, :lang FROM langs WHERE pageID='gen'"; " : Array ( [0] => Array ( [stringID] => espacemembres [fr] => fr ) [1] => Array ( [stringID] => accueil [fr] => fr ) ) Why its different im going crasy, thanks. The code : class any_process_LangManager extends any_process_Base { static $findALL = "SELECT stringID, :lang FROM langs WHERE pageID='gen'"; //langs function findALL( $lang ) { $stmt = self::$PDO->prepare(self::$findALL); $stmt->bindValue(':lang', $lang, PDO::PARAM_STR); if (!$stmt->execute()){ echo "\nPDOStatement::errorInfo():\n"; $arr = $stmt->errorInfo(); print_r($arr); } elseif (!$result = $stmt->fetchAll( PDO::FETCH_ASSOC )){ echo "\nPDOStatement ::errorInfo():\n"; $arr = $stmt->errorInfo(); print_r($arr); } else { //the result given in post : print_r($result); $res = array(); foreach ($result as $value) { $res[$value['stringID']] = $value[$lang]; } //print_r($res); //die; //return $result; } Link to comment https://forums.phpfreaks.com/topic/115869-pdo-problem/ Share on other sites More sharing options...
strangermaster Posted July 22, 2008 Author Share Posted July 22, 2008 ok i'll use this without bindparam but do not undersatand why bind works with any field in SQL but the colums names : class any_process_LangManager extends any_process_Base { // static $findALL = "SELECT :lang, stringID FROM langs WHERE pageID='gen'"; //langs gen function findALL( $lang ) { try { $stmt = self::$PDO->prepare("SELECT $lang, stringID FROM langs WHERE pageID='gen'"); //$stmt->bindParam(':lang', $lang); $stmt->execute(); $stmt->bindColumn('stringID', $stringID_); $stmt->bindColumn($lang, $lang_); while ($row = $stmt->fetch(PDO::FETCH_BOUND)) { $result[$stringID_] = $lang_; } } catch (PDOException $e) { print $e->getMessage(); } return $result; } } Link to comment https://forums.phpfreaks.com/topic/115869-pdo-problem/#findComment-596497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.