Jump to content

pdo problem


strangermaster

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.