Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2. $cfg = parse_ini_file("cfg.ini", true);
  3. class db
  4. {
  5.     public $path;
  6.     public $way;
  7.         function __construct($cfg)
  8.         {
  9.                 $this->name = $cfg['DB']['username'];
  10.                 $this->password = $cfg['DB']['password'];
  11.                 $this->dbname = $cfg['DB']['dbname'];
  12.                 $this->dhcp = $cfg['DHCP']['path'];
  13.         }
  14.         function connect()
  15.         {   global $dbconn;
  16.             $dbconn = pg_connect("host=localhost dbname=$this->dbname user=$this->name password=$this->password");
  17.         }
  18.         function select($what,$where)
  19.         {  
  20.             $query = 'SELECT '.$what.' FROM '.$where.'';
  21.             $result=pg_query($query);
  22.             $arr = pg_fetch_all($result);
  23.             print_r($arr[0]) ;
  24.         }
  25.         function dhcp($file,$i)
  26.         {
  27.                 $a=strpos($file[$i],","); //В данную переменную положил порядковый номер запятой
  28.                 $b=substr($file[$i],0,$a); // Обрезал строку до запятой,что бы получить имя ключа
  29.                 return $b;
  30.         }
  31.         function dhcp_num()
  32.         {
  33.             global $file;
  34.             $file =file($this->dhcp);
  35.             $string=count($file =file($this->dhcp));
  36.             return $string;
  37.         }
  38. }
  39.  
  40. $app=new db($cfg);
  41. $app->connect();
  42. //$app->select("idcomputer","computer");
  43. //pg_close($dbconn);
  44. //$app->dhcp();
  45. //echo $app->dhcp_num();
  46. //echo $app->dhcp($file,0);
  47. $i=0;
  48. while ($i<($app->dhcp_num()))
  49. {
  50.     $q=$app->dhcp($file,$i);echo "\n";
  51.     $i=$i+1;
  52.     $c=$app->select("cert=$q","computer");
  53.     echo "$c\n";
  54. }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement