PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- class DbConnection{
- private $mysqli_conn;
- private $last_error;
- //--- Connection data -------------
- private $URL;
- private $UserName;
- private $Password;
- private $DbName;
- //-----------------------------------
- public function __construct($URL, $UserName, $Password, $DbName){
- $this->$URL = $URL;
- $this->$UserName = $UserName;
- $this->$Password = $Password;
- $this->$DbName = $DbName;
- }
- public function connect(){
- $this->$mysqli_conn = new mysqli($this->$URL, $this->$UserName, $this->$Password, $this->$DbName);// !!!
- $this->$mysqli_conn->query('set names utf8;');
- }
- public function getLastError(){
- return $this->$last_error;
- }
- // Выборка одной записи из заданной таблицы
- public function getRow($TableName, $ID_type, $ID){
- $RowQueryResult = $this->$mysqli_conn->prepare('SELECT * FROM '.$TableName.' WHERE '.$ID_type.' = ?');
- $RowQueryResult->bind_param("s", $ID);
- $RowQueryResult->execute();
- if($RowQueryResult->affected_rows) $ResultRow = $RowQueryResult->fetch_assoc();
- else{
- $ResultRow = NULL;
- $this->$last_error = $mysqli_conn->lasr_error();
- }
- return $ResultRow;
- }
- function disconnect(){
- if($RowQueryResult->affected_rows) $RowQueryResult->close();
- $this->$mysqli_conn->close();
- }
- }