php oop crud database

Solutions on MaxInterview for php oop crud database by the best coders in the world

showing results for - "php oop crud database"
Manuela
29 Mar 2020
1<?php
2
3	class Customers
4	{
5		private $servername = "localhost";
6		private $username   = "root";
7		private $password   = "";
8		private $database   = "blog_database";
9		public  $con;
10
11
12		// Database Connection 
13		public function __construct()
14		{
15		    $this->con = new mysqli($this->servername, $this->username,$this->password,$this->database);
16		    if(mysqli_connect_error()) {
17			 trigger_error("Failed to connect to MySQL: " . mysqli_connect_error());
18		    }else{
19			return $this->con;
20		    }
21		}
22
23		// Insert customer data into customer table
24		public function insertData($post)
25		{
26			$name = $this->con->real_escape_string($_POST['name']);
27			$email = $this->con->real_escape_string($_POST['email']);
28			$username = $this->con->real_escape_string($_POST['username']);
29			$password = $this->con->real_escape_string(md5($_POST['password']));
30			$query="INSERT INTO customers(name,email,username,password) VALUES('$name','$email','$username','$password')";
31			$sql = $this->con->query($query);
32			if ($sql==true) {
33			    header("Location:index.php?msg1=insert");
34			}else{
35			    echo "Registration failed try again!";
36			}
37		}
38
39		// Fetch customer records for show listing
40		public function displayData()
41		{
42		    $query = "SELECT * FROM customers";
43		    $result = $this->con->query($query);
44		if ($result->num_rows > 0) {
45		    $data = array();
46		    while ($row = $result->fetch_assoc()) {
47		           $data[] = $row;
48		    }
49			 return $data;
50		    }else{
51			 echo "No found records";
52		    }
53		}
54
55		// Fetch single data for edit from customer table
56		public function displyaRecordById($id)
57		{
58		    $query = "SELECT * FROM customers WHERE id = '$id'";
59		    $result = $this->con->query($query);
60		if ($result->num_rows > 0) {
61			$row = $result->fetch_assoc();
62			return $row;
63		    }else{
64			echo "Record not found";
65		    }
66		}
67
68		// Update customer data into customer table
69		public function updateRecord($postData)
70		{
71		    $name = $this->con->real_escape_string($_POST['uname']);
72		    $email = $this->con->real_escape_string($_POST['uemail']);
73		    $username = $this->con->real_escape_string($_POST['upname']);
74		    $id = $this->con->real_escape_string($_POST['id']);
75		if (!empty($id) && !empty($postData)) {
76			$query = "UPDATE customers SET name = '$name', email = '$email', username = '$username' WHERE id = '$id'";
77			$sql = $this->con->query($query);
78			if ($sql==true) {
79			    header("Location:index.php?msg2=update");
80			}else{
81			    echo "Registration updated failed try again!";
82			}
83		    }
84			
85		}
86
87
88		// Delete customer data from customer table
89		public function deleteRecord($id)
90		{
91		    $query = "DELETE FROM customers WHERE id = '$id'";
92		    $sql = $this->con->query($query);
93		if ($sql==true) {
94			header("Location:index.php?msg3=delete");
95		}else{
96			echo "Record does not delete try again";
97		    }
98		}
99
100	}
101?>
Manuel
17 Mar 2019
1-- Table structure for table `customers`
2--
3
4CREATE TABLE `customers` (
5  `id` int(100) NOT NULL,
6  `name` varchar(100) NOT NULL,
7  `email` varchar(100) NOT NULL,
8  `username` varchar(100) NOT NULL,
9  `password` varchar(100) NOT NULL
10) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
queries leading to this page
php oop crud tutorial step by stepphp and crudcrud operation in php using oops conceptcrud table phpoops crud operation in phpphp with crud operationsphp oop crud classuse the oops concept to create a crud operation in phpphp crud mysql and oopphp crud crud in oop php with apiphp object oriented mysql crudoop php crudcrud queries oop phpwhat is php crudcrud php oopphp oop crud examplephp crud tablephp crud from databasephp crud oopphp oop crud databasecrud oop phpcrud in oop phpphp mysql oop crud tutorialphp crud from databasephp oop crud tutorial pdfphp crud operation for state table in php oopsql crud phpbuild a php crud api using oopcrud operation in php using oopsphp odbc crud exampleoop crud operation in phpphp crud object orientedphp oop crud operations using oopdo we use oop in your full crud project phpphp make crud oopoop crud tutorialphp oop crud tutorial pdfphp crud oop example class employeesphp object oriented crudcrud oop of phpphp oops crudcrud using oop in phpcrud operation in php oopcrud operation in oop phpcrud databaseoop crud design pattern phpfunction to crud database in phpphp oop crud programming examplescomplete crud operation with oop php mysql database php crud using oopcrud application in php using oopshow to use oop in crud system in phpphp oop crud using traitshow to crud operation in phpphp sql server crudcreate crud oop phpphp oop crudobject oriented crud phpphp crud oop examplephp crud operation using oopswhat is crud phpcrud operations in php oopcrud with oop in phpcrud php objectphp oops crud operationphp oop crud tutorialphp crud oop class employeesphp crud using oopshow to do crud operation using phpphp oop crud sample codephp oop crud rest api crud php oriented objectbest way to do crud operations without database phpoop crud login phpcrud php with oopoops concept crud operation in phpsimple php object oriented crudoop php crudoop crud with php projectcrud php databasephp oop crud database