note 127055 added to intro.mysqli

From: Date: Sat, 14 May 2022 13:27:25 +0000
Subject: note 127055 added to intro.mysqli
Groups: php.notes 
Request: Send a blank email to php-notes+get-218381@lists.php.net to get a copy of this message
// 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); } } ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.47 (proxied: 88.14.147.169) ---- Manual Page -- https://php.net/manual/en/intro.mysqli.php Edit -- https://main.php.net/note/edit/127055 Del: integrated -- https://main.php.net/note/delete/127055/integrated Del: useless -- https://main.php.net/note/delete/127055/useless Del: bad code -- https://main.php.net/note/delete/127055/bad+code Del: spam -- https://main.php.net/note/delete/127055/spam Del: non-english -- https://main.php.net/note/delete/127055/non-english Del: in docs -- https://main.php.net/note/delete/127055/in+docs Del: other reasons-- https://main.php.net/note/delete/127055 Reject -- https://main.php.net/note/reject/127055 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218381) next »