<?php
// Target : Connecting to phpmyadmin and creating table thorugh oop way.
// Note : Try this in your local server. It works 100%.
Class Connect {
var $user = "root";
var $pass = "jqFKJHT6mbQuDp26";
var $host = "localhost";
var $database = "jack";
var $dbc;
var $db;
// function or method declaration.
function connectMySql(){
// 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 jack';
// Syntax --->mysqli_query(connection,query,resultmode);
if(mysqli_query($dbc, $db)) {
echo"Database created through oops way / Exists Already.<br> ";
}else {
echo'error creating database or database already exists'. mysqli_error($dbc);
}
} // end of function.
function tableCreate(){
//mysqli_connect(host,username,password,dbname,port,socket);
$dbc = mysqli_connect("$this->host","$this->user","$this->pass",
"$this->database");
$q = 'CREATE TABLE IF NOT EXISTS `kschool` (
`Name` text NOT NULL,
`Class` int(5) NOT NULL,
`RollNo` int(5) NOT NULL,
`Tamil` int(5) NOT NULL,
`English` int(5) NOT NULL,
`Maths` int(5) NOT NULL,
`Science` int(5) NOT NULL,
`Social` int(5) NOT NULL,
`Total` int(5) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
';
// Syntax --->mysqli_query(connection,query,resultmode);
if(mysqli_query($dbc, $q)) {
echo"Table created through oops way / Exists Already ";
}else {
echo'error creating table or table already exists'. mysqli_error($dbc);
}
}// end of table creation function.
}// end of class connect.
//Object creation.
$x = new Connect();
//Accessing method.
//$x->connectMysql();
$x->createdb();
$x->tableCreate();
?>
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.