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
<?php require_once('config.php'); class Database{ private $hCon; public function __construct(){ $this->hCon = new mysqli($cfg['db']['host'], $cfg['db']['user'], $cfg['db']['password'], $cfg['db']['name'], $cfg['db']['port']); if (mysqli_connect_errno()){ throw new Exception("Nie mozna nawiązać połączenia z bazą danych", E_USER_ERROR); } } public function __destruct(){ @mysqli_close($this->hCon); } } public function select($sql){ $hRes = $this->hCon->query($sql); if ($hRes != TRUE){ throw new Exception($this->hCon->error); } while ($row = $hRes->fetch_assoc()){ $arReturn[] = $row; } return $arReturn; } public function insert($table, $arFieldValues){ // Tablica dla klauzuli VALUES // zabezpieczenie real_escape_string foreach($values as $val){ $val = "'" . $this->hCon->real_escape_string($val) . "'"; } $escVals[] = $val; } // instrukcja SQL $sql = "insert into $table ("; $sql .= ') values('; $sql .= ')'; $hRes = $this->hCon->query($sql); if ($hRes != TRUE){ throw new Exception($this->hCon->error); } return $this->hCon->affected_rows; } public function update($table, $arFieldValues, $arConditions){ // tablica dla klauzuli SET foreach ($arFieldValues as $field => $val){ $val = "'" . $this->hCon->real_escape_string($val) . "'"; } $arUpdates[] = "$field = $val"; } // tablica dla klauzuli WHERE foreach ($arConditions as $field => $val){ $val = "'" . $this->hCon->real_escape_string($val) . "'"; } $arWhere[] = "$field = $val"; } $sql = "UPDATE $table SET "; $hRes = $this->hCon->query($sql); if ($hRes != TRUE){ throw new Exception($this->hCon->error); } return $this->hCon->affected_rows; } public function delete($table, $arConditions){ // tablica dla klauzuli WHERE foreach ($arConditions as $field => $val){ $val = "'" . $this->hCon->real_escape_string($val) . "'"; } $arWhere[] = "$field = $val"; } $hRes = $this->hCon->query($sql); if ($hRes != TRUE){ throw new Exception($this->hCon->error); } return $this->hCon->affected_rows; } } ?>
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)