Guest User

Untitled

a guest
Aug 1st, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. load config.php with in a class
  2. <?php
  3. $__error_reporting_level=1;
  4. $server='localhost';
  5. $user='root';
  6. $password='';
  7. $dbase='eauction';
  8. ?>
  9.  
  10. <?php
  11. include ('config.php');
  12. error_reporting($__error_reporting_level);
  13.  
  14. class sql
  15. {
  16. function connect()
  17. {
  18. $connections = mysql_connect($server, $user,$password) or die ('Unabale to connect to the database');
  19. mysql_select_db($dbase) or die ('Unable to select database!');
  20. return;
  21. }
  22.  
  23. function login($email, $pwd)
  24. {
  25. $this->connect();
  26. $result = $this->qry("SELECT uid,nameF FROM user WHERE email='".$email."' AND password='".$pwd."'");
  27. $row=mysql_fetch_array($result);
  28. if (mysql_num_rows($result)>0)
  29. return array($row[0],$row[1]);
  30. else
  31. return array(0,0);
  32. }
  33. }
  34. ?>
  35.  
  36. include ('core/sql.php');
  37. $obj = new sql;
  38. $data=$obj->login($email,$pwd);
  39. print_r($data);
  40.  
  41. <?php
  42. class ConnectionSettings {
  43. private $hostname = 'localhost';
  44. private $username = 'root';
  45. private $password = '';
  46. private $db = 'cordiac_db';
  47. protected $connLink;
  48.  
  49. // protected 'connect()' method
  50. protected function connect(){
  51.  
  52. // establish connection
  53. if(!$this->connLink = mysql_connect($this->hostname, $this->username, $this->password)) {
  54. throw new Exception('Error connecting to MySQL: '.mysql_error());
  55. }
  56.  
  57. // select database
  58. if(!mysql_select_db($this->db, $this->connLink)) {
  59. throw new Exception('Error selecting database: '.mysql_error());
  60. }
  61. }
  62. }
  63.  
  64. include ('config.php');
  65. // Now all your variables are defined at global scope!!!
  66. error_reporting($__error_reporting_level);
  67.  
  68. class sql
  69. {
  70. // Pass as params to the function
  71. function connect($server, $user, $password, $dbase)
  72. {
  73. $connections = mysql_connect($server, $user,$password) or die ('Unabale to connect to the database');
  74. mysql_select_db($dbase) or die ('Unable to select database!');
  75. return;
  76. }
  77. // etc...
  78. // etc...
  79. }
  80.  
  81. class sql
  82. {
  83. public $server;
  84. public $user;
  85. public $password;
  86. public $dbase;
  87.  
  88. public function __construct($server, $user, $password, $dbase) {
  89. $this->server = $server;
  90. $this->user = $user;
  91. // etc...
  92. $connections = mysql_connect($this->server, $this->user, $this->password);
  93. }
  94. }
  95.  
  96. server=test
  97. user=root
  98. pass=pass
  99. dbname=mydb
  100.  
  101. class A {
  102.  
  103. public $config;
  104.  
  105. public function __construct() {
  106. $this->config = parse_ini_file('config.ini', true);
  107. }
  108.  
  109. public function sql {
  110. $connections = mysql_connect($this->config['server'], $this->config['user'],$this->config['password']) or die ('Unabale to connect to the database');
  111. mysql_select_db($this->config['dbase']) or die ('Unable to select database!');
  112. return;
  113. }
  114. }
  115.  
  116. function connect()
  117. {
  118. include ('config.php');
  119. $connections = mysql_connect($server, $user,$password) or die ('Unabale to connect to the database');
  120. mysql_select_db($dbase) or die ('Unable to select database!');
  121. return;
  122. }
  123.  
  124. config.php
  125. define('SERVER',$server);
  126. define('USER',$user);
  127. define('PASSWORD',$password);
  128. define('DBASE',$dbase);
  129.  
  130.  
  131.  
  132. ----------class----------
  133. <?php
  134. include ('config.php');
  135. error_reporting($__error_reporting_level);
  136.  
  137. class sql
  138. {
  139. protected $server=SERVER;
  140. protected $user=USER;
  141. protected $password=PASSWORD;
  142. protected $dbase=DBASE;
  143. private function connect()
  144. {
  145. $connections = mysql_connect($this->server, $this->user,$this->password) or die ('Unabale to connect to the database');
  146. mysql_select_db($this->dbase) or die ('Unable to select database!');
  147. return;
  148. }
  149. ........
  150. ........
Add Comment
Please, Sign In to add comment