Sql 

- PHP


: softtime
..
. , .

, - , (). , "" . (1, 45, 100, 378 ..) , integer. - . - http://www.php.net/manual/ru/language.types.php. , - .

, . , . , . , , . , , . .

. , , . , - . - - .

, , , . , . , . . , , , , , . . , , . .. , . , , , , . - , . , . . , , . , , .

. .

, , . , email . .

classGuestBook
{
private$name;
private$email;
private$msg;

publicfunction__construct($name,$email,$msg)
{
$this->name=$name;
$this->email=$email;
$this->msg=$msg;
}
}
?>


-, . -, private, , , . -, __construct($name, $email, $msg). . , , , , . , .

-, $this. $this , . , , $this: $this->name $name - .

, . , .

classGuestBook
{
private$name;
private$email;
private$msg;

publicfunction__construct($name,$email,$msg)
{
$this->name=$name;
$this->email=$email;
$this->msg=$msg;
}

publicfunctiongetName()
{
return$this->name;
}
publicfunctiongetEmail()
{
return$this->email;
}
publicfunctiongetMsg()
{
return$this->msg;
}
}
?>


.

, . MySQL. DataBase - . . . (SELECT) :

publicfunctionSelect()
{
$sql="SELECTname,email,msgFROMguestbook";
$dbArray=$this->db->Db2Array();
foreach($dbArrayas$rows)
{
$outPut[]=newGuestBook($rows['name'],$rows['email'],$rows['msg'],$this->db);
}
return$outPut;
}
?>


:

publicfunctionInsert()
{
$sql="INSERTINTOguestbook(name,email,msg)VALUES('{$this->name}','{$this->email}','{$this->msg}')";
if($this->db->Insert($sql)===TRUE)
returnTRUE;
returnFALSE;
}
?>


GuestBook, TRUE, , FALSE - .

Select() c SQL- .
$dbArray. . GuestBook, . , .

SQL-, (INSERT). , (TRUE), - (FALSE).

Web- , , . Select, DataBase. , - DataBase. . , DataBase, , $db.

publicfunctionsetDb($db)
{
$this->db=$db;
}
?>


, $db - DataBase. :

publicfunctionsetDb($db)
{
$this->db=newDataBase("login","password","host","database");//-.
}
?>


DataBase . :)
, : , .

classGuestBook
{
private$name;
private$email;
private$msg;

publicfunction__construct($name,$email,$msg)
{
$this->name=$name;
$this->email=$email;
$this->msg=$msg;
}

publicfunctiongetName()
{
return$this->name;
}
publicfunctiongetEmail()
{
return$this->email;
}
publicfunctiongetMsg()
{
return$this->msg;
}
} classGuestBookDb
{
private$db;

publicfunction__construct($db)
{
$this->db=$db;
}
publicfunctionSelect()
{
$sql="SELECTname,email,msgFROMguestbook";
$dbArray=$this->db->Db2Array();
foreach($dbArrayas$rows)
{
$outPut[]=newGuestBook($rows['name'],$rows['email'],$rows['msg']);
}
return$outPut;
}
publicfunctionInsert($obj)
{
$name=$obj->getName();
$email=$obj->getEmail();
$msg=$obj->getMsg();

$sql="INSERTINTOguestbook(name,email,msg)VALUES('$name','$email','$msg')";
if($this->db->Insert($sql)===TRUE)
returnTRUE;
returnFALSE;
}
}
?>


: -, Select, . GuestBook, GuestBookDb. DataBase. -, Insert(). - GuestBook - , . .

- : , , . . .

. - . , , .. . . (private), .. . (private), , (public) . , , . , . $db. , , .

, , .

- :

  • Public - - , , , .
  • Private - , .
  • Protected - , , , , .
. , DataBase. . ? , .. (, , ) .
-, , , - . , , , - . - .. .

. , . , email Web- ICQ. , GuestBook.

classSharedGuestBookextendsGuestBook
{
private$url;
private$icq;

publicfunction__construct($name,$email,$msg,$url,$icq)
{
parent::__construct($name,$email,$msg);
$this->url=$url;
$this->icq=$icq;
}
publicfunctiongetUrl()
{
return$this->url;
}
publicfunctiongetIcq()
{
return$this->icq;
}
}
?>


, - - - .

- parent :: __construct($name, $email, $msg); - (http://www.php.net/manual/ru/language.oop5.paamayim-nekudotayim.php): , -, PHP , -. , . [url = http://www.php.net/manual/ru/language.oop5.decon.php] [/url], "" .

extends . GuestBookDb .

classSharedGuestBookDbextendsGuestBookDb
{
publicfunctionSelect()
{
$sql="SELECTname,email,msg,url,icqFROMnew_guestbook";
$dbArray=$this->db->Db2Array();
foreach($dbArrayas$rows)
{
$outPut[]=newSharedGuestBook($rows['name'],$rows['email'],$rows['msg'],$rows['url'],$rows['icq']);
}
return$outPut;
}
publicfunctionInsert($obj)
{
$name=$obj->getName();
$email=$obj->getEmail();
$msg=$obj->getMsg();
$url=$obj->getUrl();
$icq=$obj->getIcq();

$sql="INSERTINTOnew_guestbook(name,email,msg,url,icq)VALUES('$name','$email','$msg','$url','$icq')";
if($this->db->Insert($sql)===TRUE)
returnTRUE;
returnFALSE;
}
}
?>


, .. . - , , :)
, , . final. .

classSomeClass
{
private$var;

finalpublicfunctionPrintVar()
{
echo$var;
}
publicfunctionSetVar()
{
$this->var="FromSomeClass";
}
}
classSomeClassNewextendsSomeClass
{
publicfunctionSetVar()
{
$this->var="FromSomeClassNew";
}
}
?>


PrintVar(), .
final, .

. , .

. . . , , , , . , . - , .. , , , , . , . , , , , , - , . . GuestBook

$guest_book=newGuestBook($name,$email,$msg);
?>


, :

$var=newSomeClass();
?>


, - parent :: __construct();

. . . , __destruct(). : , , .. -, , - parent :: __destruct();

. . , . . , . , , . , , , . , . , , . , , , - . , , .

, . . , . .. , . , . , .

GuestBookDb, SharedGuestBookDb , GuestBookDb.

abstractclassGbDb
{
private$db;

publicfunction__construct($db)
{
$this->db=$db;
}

abstractpublicfunctionSelect();
abstractpublicfunctionInsert($obj);
} classGuestBookDbextendsGbDb
{
publicfunctionSelect()
{
//
}
publicfunctionInsert($obj)
{
//
}
}
classSgbDbextendsGuestBookDb
{
publicfunctionSelect()
{
//
}
publicfunctionInsert($obj)
{
//
}
}
?>


, , , . ? , , ? . , .. abstract. , .. , . , . , . . .

interfaceGbDb
{
functionSelect();
functionInsert($obj);
} classGuestBookDbimplementsGbDb
{
publicfunctionSelect()
{
//
}
publicfunctionInsert($obj)
{
//
}
}
classSgbDbextendsGuestBookDb
{
publicfunctionSelect()
{
//
}
publicfunctionInsert($obj)
{
//
}
}
?>


. , .

interfaceGbDb
{
functionSelect();
functionInsert($obj);
}
interfaceGbDbNew
{
functionUpdate($id,$obj);
functionSelectWithId($id);
}
classGuestBookDbimplementsGbDb,GbDbNew
{
publicfunctionSelect()
{
//
}
publicfunctionInsert($obj)
{
//
}
publicfunctionUpdate($id,$obj)
{
//
}
publicfunctionSelectWithId($id)
{
//
}
}
classSgbDbextendsGuestBookDb
{
publicfunctionSelect()
{
//
}
publicfunctionInsert($obj)
{
//
}
publicfunctionUpdate($id,$obj)
{
//
}
publicfunctionSelectWithId($id)
{
//
}
}
?>


, . . extends.

- . , , , . , .



 

 Oracle Oracle Business Intelligence Applications.
 MCITP: Database Administrator.
  Sybase PowerDesigner QuickStart. .
 MySQL " ".
  SQLBase 11.6.


 Sql 

2017 Team.Furia.Ru.
.