Category Archives: PHP

Best web development language if used right

PHP Mysql extending class

So, lets say you want to extend php/mysql class we were talking about earlier.

class nastavak extends baza {

private $nast;
private $drugi;

public function __construct(){
echo "This is the extended class";
parent::__construct("","root","","test");
parent::sqlquery("select * from imena");
parent::stampaj();
}
}

What happened here? Well, we have added another class on top of baza class and that way we have extended it. It means new class (extended) has everything from parent class (baza) and what we have added inside of it (nastavak).

Overriding in the next article.

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.