PHP OOP -> Database Creation.

<?php // Target : Connecting to phpmyadmin thorugh oop way. // Note : Try this in your local server. It works 100%. //define syntax -----> define(name, value, bool) Class Connect { var $user = "root"; var $pass = "jqFKJHT6mbQuDp26"; var $host = "localhost"; var $dbc; var $db; // function or method declaration. function connectMySql(){ //$dbc = new mysqli($this->server,$this->user,$this->password); // Syntax -----> //mysqli_connect(host,username,password,dbname,port,socket); $dbc = mysqli_connect("$this->host","$this->user","$this->pass"); //Status of connection. if($dbc->connect_error) { die("Not Connected" .$dbc->connect_error); } else { echo "Connected to server thorugh oops ways!!!.<br>"; } }//end of function connectMysql. // Database Creation function createdb() { $dbc = mysqli_connect("$this->host","$this->user","$this->pass"); $db = 'CREATE DATABASE IF NOT EXISTS queen'; // Syntax --->mysqli_query(connection,query,resultmode); if(mysqli_query($dbc, $db)) { echo"Database created through oops way / Exists Already "; }else { echo'error creating database or database already exists'. mysqli_error($dbc); } } // end of function. }// end of class connect. //Object creation. $x = new Connect(); //Accessing method. $x->connectMysql(); $x->createdb(); ?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.