witam,
korzystałem z ksiązki i znalazłem tutaj te klase co jest w temacie
Temat: phpObsluga_SQL
czy mógłby ktoś odpowiedzieć na ostatniego posta?

tutaj jest kod klasy
  1. <?php
  2.  
  3. require_once('config.php');
  4.  
  5. class Database{
  6.  
  7.   private $hCon;
  8.  
  9.   public function __construct(){
  10.       global $cfg; // globalna tablica asosjacyjna $cfg
  11.  
  12.       $this->hCon = new mysqli($cfg['db']['host'],
  13.                                $cfg['db']['user'],
  14.                                $cfg['db']['password'],
  15.                                $cfg['db']['name'],
  16.                                $cfg['db']['port']);
  17.       if (mysqli_connect_errno()){
  18.           throw new Exception("Nie mozna nawiązać połączenia z bazą danych", E_USER_ERROR);
  19.       }
  20.   }
  21.   public function __destruct(){
  22.       if (is_resource($this->hCon)){
  23.           @mysqli_close($this->hCon);
  24.       }
  25.   }
  26.   public function select($sql){
  27.       $hRes = $this->hCon->query($sql);
  28.       if ($hRes != TRUE){
  29.           throw new Exception($this->hCon->error);
  30.       }
  31.      
  32.       $arReturn = array();
  33.       while ($row = $hRes->fetch_assoc()){
  34.           $arReturn[] = $row;
  35.       }
  36.      
  37.       return $arReturn;
  38.   }
  39.   public function insert($table, $arFieldValues){
  40.       $fields = array_keys($arFieldValues);
  41.       $values = array_values($arFieldValues);
  42.      
  43.       // Tablica dla klauzuli VALUES
  44.       // zabezpieczenie real_escape_string
  45.       $escVals = array();
  46.       foreach($values as $val){
  47.           if (!is_numeric($val)){
  48.               $val = "'" . $this->hCon->real_escape_string($val) . "'";
  49.           }
  50.           $escVals[] = $val;
  51.       }
  52.      
  53.       // instrukcja SQL
  54.       $sql = "insert into $table (";
  55.       $sql .= join(', ', $fields);
  56.       $sql .= ') values(';
  57.       $sql .= join(', ', $escVals);
  58.       $sql .= ')';
  59.      
  60.       $hRes = $this->hCon->query($sql);
  61.       if ($hRes != TRUE){
  62.           throw new Exception($this->hCon->error);
  63.       }
  64.      
  65.       return $this->hCon->affected_rows;
  66.   }
  67.   public function update($table, $arFieldValues, $arConditions){
  68.       // tablica dla klauzuli SET
  69.       $arUpdates = array();
  70.       foreach ($arFieldValues as $field => $val){
  71.           if (!is_numeric($val)){
  72.               $val = "'" . $this->hCon->real_escape_string($val) . "'";
  73.           }
  74.           $arUpdates[] = "$field = $val";
  75.       }
  76.      
  77.       // tablica dla klauzuli WHERE
  78.       $arWhere = array();
  79.       foreach ($arConditions as $field => $val){
  80.           if (!is_numeric($val)){
  81.               $val = "'" . $this->hCon->real_escape_string($val) . "'";
  82.           }
  83.           $arWhere[] = "$field = $val";
  84.       }
  85.      
  86.       $sql = "UPDATE $table SET ";
  87.       $sql .= join(', ', $arUpdates);
  88.       $sql .= ' WHERE ' . join(' AND ', $arWhere);
  89.      
  90.       $hRes = $this->hCon->query($sql);
  91.       if ($hRes != TRUE){
  92.           throw new Exception($this->hCon->error);
  93.       }
  94.      
  95.       return $this->hCon->affected_rows;
  96.   }
  97.   public function delete($table, $arConditions){
  98.       // tablica dla klauzuli WHERE
  99.       $arWhere = array();
  100.       foreach ($arConditions as $field => $val){
  101.           if (!is_numeric($val)){
  102.               $val = "'" . $this->hCon->real_escape_string($val) . "'";
  103.           }
  104.           $arWhere[] = "$field = $val";
  105.       }
  106.      
  107.       $sql = "DELETE FROM $table WHERE " . join(' AND ', $arWhere);
  108.      
  109.       $hRes = $this->hCon->query($sql);
  110.       if ($hRes != TRUE){
  111.           throw new Exception($this->hCon->error);
  112.       }
  113.      
  114.       return $this->hCon->affected_rows;
  115.   }
  116. }
  117.  
  118. ?>


a tutaj treść o co mi chodzi:

mam w tabeli 2 kolumny - id i nazwa - jak zrobic aby id było przypisane innej zmiennej a nazwa innej tak żebym mogł tego swobodnie uzywac np w listach rozwijanych (do których jest mi to potrzebne) czy ogólnie do prezentacji danych jako tabeli?

moje pytanie jak najbardziej dalej aktualne (dzięki nospor)