Este equipo de expertos pasados muchos días de trabajo y de recopilar de datos, han obtenido la solución, queremos que te sea de gran utilidad en tu proyecto.
Ejemplo 1: base de datos php oop crud
classCustomersprivate$servername="localhost";private$username="root";private$password="";private$database="blog_database";public$con;// Database Connection publicfunction__construct()$this->con=newmysqli($this->servername,$this->username,$this->password,$this->database);if(mysqli_connect_error())trigger_error("Failed to connect to MySQL: ".mysqli_connect_error());elsereturn$this->con;// Insert customer data into customer tablepublicfunctioninsertData($post)$name=$this->con->real_escape_string($_POST['name']);$email=$this->con->real_escape_string($_POST['email']);$username=$this->con->real_escape_string($_POST['username']);$password=$this->con->real_escape_string(md5($_POST['password']));$query="INSERT INTO customers(name,email,username,password) VALUES('$name','$email','$username','$password')";$sql=$this->con->query($query);if($sql==true)header("Location:index.php?msg1=insert");elseecho"Registration failed try again!";// Fetch customer records for show listingpublicfunctiondisplayData()$query="SELECT * FROM customers";$result=$this->con->query($query);if($result->num_rows>0)$data=array();while($row=$result->fetch_assoc())$data[]=$row;return$data;elseecho"No found records";// Fetch single data for edit from customer tablepublicfunctiondisplyaRecordById($id)$query="SELECT * FROM customers WHERE id = '$id'";$result=$this->con->query($query);if($result->num_rows>0)$row=$result->fetch_assoc();return$row;elseecho"Record not found";// Update customer data into customer tablepublicfunctionupdateRecord($postData)$name=$this->con->real_escape_string($_POST['uname']);$email=$this->con->real_escape_string($_POST['uemail']);$username=$this->con->real_escape_string($_POST['upname']);$id=$this->con->real_escape_string($_POST['id']);if(!empty($id)&&!empty($postData))$query="UPDATE customers SET name = '$name', email = '$email', username = '$username' WHERE id = '$id'";$sql=$this->con->query($query);if($sql==true)header("Location:index.php?msg2=update");elseecho"Registration updated failed try again!";// Delete customer data from customer tablepublicfunctiondeleteRecord($id)$query="DELETE FROM customers WHERE id = '$id'";$sql=$this->con->query($query);if($sql==true)header("Location:index.php?msg3=delete");elseecho"Record does not delete try again";?>
Ejemplo 2: base de datos php oop crud
-- Table structure for table `customers`--CREATETABLE`customers`(`id`int(100)NOTNULL,`name`varchar(100)NOTNULL,`email`varchar(100)NOTNULL,`username`varchar(100)NOTNULL,`password`varchar(100)NOTNULL)ENGINE=InnoDB DEFAULTCHARSET=utf8mb4;
Aquí puedes ver las comentarios y valoraciones de los lectores
Acuérdate de que tienes la capacidad de parafrasear si encontraste tu escollo .
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)