note 127055 deleted from intro.mysqli by cmb

From: Date: Sat, 14 May 2022 16:16:05 +0000
Subject: note 127055 deleted from intro.mysqli by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218383@lists.php.net to get a copy of this message
Note Submitter: I like php ---- // snippet to CRUD $bd = new myDB(); $con= $bd->connect(); $bd->insertar("INSERT INTO table (id,name) VALUES (5,'my name')"); $bd->delete("DELETE FROM table where id=5"); $bd->update("UPDATE table SET name='otr name' where id=5"); $data=[]; $res=$bd->select("SELECT * FROM table"); while ($row = mysqli_fetch_assoc($res)) { $data[]=$row; } class myDB { private $con; private $user; private $host; private $pass; private $db; public function __construct() { $this->user = "root"; $this->host = "localhost"; $this->pass = ""; $this->db = "5ta_cliente"; } public function connect() { $this->con = new mysqli($this->host,$this->user,$this->pass,$this->db); if ($this->con->connect_errno) { printf("Error: %s\n", $mysqli->connect_error); exit(); } else { return $this->con; } } // insertar eliminar update public function select($query) { $res = $this->con->query($query); if (!$res) { echo "Error ..."; } return $res; } public function insert($query) { if (!$this->con->query($query)) { echo "Error ..."; } } public function update($query) { $this->insert($query); } public function delete($query) { $this->insert($query); } }

« previous php.notes (#218383) next »