Skip to main content

Posts

Showing posts from February, 2019

Insertion

<?php include_once ( "function.php" ); $insertdata = new DB_con(); if ( isset ( $_POST [ 'submit' ])) { $fname = $_POST [ 'fname' ]; $email = $_POST [ 'email' ]; $contact = $_POST [ 'contact' ]; $gender = $_POST [ 'gender' ]; $education = $_POST [ 'education' ]; $adrss = $_POST [ 'address' ]; $sql = $insertdata ->insert( $fname , $email , $contact , $gender , $education , $adrss ); if ( $sql ) { echo "<script>alert('Data inserted');</script>" ; } else { echo "<script>alert('Data not inserted');</script>" ; } } ?> <! DOCTYPE html > < html lang ="en" > < head > < meta http-equiv ="content-type" content ="text/html; charset=UTF-8" > < meta charset ="utf-8" > < title > OOP EXAMPLE </ title > < meta name ="generator" content ="Bootply...

AutoLoad

Need of PHP Autoload function: - When the number of classes grows, it is quite tedious to call require_once() function everywhere you use the classes. Fortunately, PHP provides a mechanism that allows you to load class files automatically whenever you try to create an object from a non-existent class in the context of the current script file. PHP Autoload function: - PHP will call __autoload() function automatically whenever you create an object from a nonexistent class. __autoload() which is automatically called when your code references a class or interface that hasn't been loaded yet. The major drawback to the __autoload() function is that you can only provide oneautoloader with it. Syntax:- autoload.php function __autoload($className) { $className = str_replace('..', '', $className); require_once("classes/$className.php"); } This autoload.php file must be include/require in your page to run autoloader Demo.php- it is a sample class a=$a; }...

Update and delete Using Function

User Define Function:                A function is a block of statements that can be used repeatedly in a program.                A function will not execute immediately when a page loads.                A function will be executed by a call to the function. Syntax:                Function function_name()         //function define without parameters                {                                        ...

Insert Data Using Function

Insert data using function First , We are going to create a class for database connection. This class has two main methods , one is connect which contains connectivity code with PHP and MYSQL. Another method is saveRecord() . It has one mandatory argument that is first argument(database table name) and another arguments are data inputted by users using html form. Example : 1.       Database Connection Class: <?php class Database {                    public $conn;     var $dbhost = 'localhost';     var $dbuser = 'root';     var $dbpass = '';     var $dbase = 'usermanagementsystem';     public function __construct() {          $this->conn = mysqli_connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dba...

View Data Using function

                              VIEW DATA USING FUNCTION Firstly, we wil need a database connection and for that we are going to create one class. The class is having one function __construct(), which is having the database connectivity. 1.       conn.php <?php session_start(); define('DB_SERVER', 'localhost'); define('DB_USER', 'root'); define('DB_PASS', ''); define('DB_NAME', 'puvvaa'); class db_con {     var $dbh=NULL;     function __construct() {         $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);         $this->dbh = $con;         if (mysqli_connect_errno()) {           ...