PHP Mysql class for websites

I had some free time and decided to write one simple php class for manipulating mysql. It’s really simple code, it can help new programmers learn how to build their own classes.

<?php

class baza {

 private $username;
 private $password;
 private $local;
 private $errors;
 private $resource1;
 private $db_sel;
 private $sqlupit;

 public function __construct($l="localhost",$u, $p, $db_selected){
 $this->username=$u;
 $this->password=$p;
 $this->local=$l;
 $this->db_sel=$db_selected;
 $this->conn();
 $this->db_selected();
 $this->listaj_db();
 }

 private function conn(){
 $this->resource1=mysql_connect($this->local,$this->username,$this->password);
 if (!$this->resource1){
 echo "Postoji problem sa konekcijom <br />";
 }
 else {
 echo "Sve je super <br />";
 }
 }

 private function db_selected(){
 mysql_select_db($this->db_sel);
 }

 private function listaj_db(){
 $result = mysql_query("SHOW DATABASES"); 
 while ($row = mysql_fetch_array($result)) { 
 echo $row[0]."<br>"; 
 }
 
 }
 
 public function sqlquery($n){
 $this->sqlupit=mysql_query($n);
 }
 
 public function stampaj(){
 //$result = mysql_query("SHOW DATABASES"); 
 while ($row = mysql_fetch_array($this->sqlupit)) { 
 echo $row[1]."<br>"; 
 }

 }
}

$n=new baza("","root","","test");
$n->sqlquery("select * from imena");
$n->stampaj();

?>

Please comment if you have some questions.

Leave a Reply

Your email address will not be published. Required fields are marked *