Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2. class MyDB{
  3. private $spojeni;
  4.  
  5. function __construct($type,$host,$user,$pass,$name){
  6. $options=array(
  7. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  8. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
  9. );
  10. $this->spojeni= @new PDO("$type:host=$host;dbname=$name",$user,$pass,$options);
  11. }
  12.  
  13. function query($query,$param=Array()){
  14. $navrat=$this->spojeni->prepare($query);
  15. $navrat->execute($param);
  16. return $navrat->rowCount();
  17. }
  18.  
  19. function queryOne($query,$param=Array()){
  20. $navrat=$this->spojeni->prepare($query);
  21. $navrat->execute($param);
  22. return $navrat->fetch(PDO::FETCH_ASSOC);
  23. }
  24.  
  25. function queryAll($query,$param=Array()){
  26. $navrat=$this->spojeni->prepare($query);
  27. $navrat->execute($param);
  28. return $navrat->fetchAll(PDO::FETCH_ASSOC);
  29. }
  30. function getID($what){
  31. $value=$this->queryOne("SELECT currval('$what') AS lastid");
  32. return $value['lastid'];
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement