Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- load config.php with in a class
- <?php
- $__error_reporting_level=1;
- $server='localhost';
- $user='root';
- $password='';
- $dbase='eauction';
- ?>
- <?php
- include ('config.php');
- error_reporting($__error_reporting_level);
- class sql
- {
- function connect()
- {
- $connections = mysql_connect($server, $user,$password) or die ('Unabale to connect to the database');
- mysql_select_db($dbase) or die ('Unable to select database!');
- return;
- }
- function login($email, $pwd)
- {
- $this->connect();
- $result = $this->qry("SELECT uid,nameF FROM user WHERE email='".$email."' AND password='".$pwd."'");
- $row=mysql_fetch_array($result);
- if (mysql_num_rows($result)>0)
- return array($row[0],$row[1]);
- else
- return array(0,0);
- }
- }
- ?>
- include ('core/sql.php');
- $obj = new sql;
- $data=$obj->login($email,$pwd);
- print_r($data);
- <?php
- class ConnectionSettings {
- private $hostname = 'localhost';
- private $username = 'root';
- private $password = '';
- private $db = 'cordiac_db';
- protected $connLink;
- // protected 'connect()' method
- protected function connect(){
- // establish connection
- if(!$this->connLink = mysql_connect($this->hostname, $this->username, $this->password)) {
- throw new Exception('Error connecting to MySQL: '.mysql_error());
- }
- // select database
- if(!mysql_select_db($this->db, $this->connLink)) {
- throw new Exception('Error selecting database: '.mysql_error());
- }
- }
- }
- include ('config.php');
- // Now all your variables are defined at global scope!!!
- error_reporting($__error_reporting_level);
- class sql
- {
- // Pass as params to the function
- function connect($server, $user, $password, $dbase)
- {
- $connections = mysql_connect($server, $user,$password) or die ('Unabale to connect to the database');
- mysql_select_db($dbase) or die ('Unable to select database!');
- return;
- }
- // etc...
- // etc...
- }
- class sql
- {
- public $server;
- public $user;
- public $password;
- public $dbase;
- public function __construct($server, $user, $password, $dbase) {
- $this->server = $server;
- $this->user = $user;
- // etc...
- $connections = mysql_connect($this->server, $this->user, $this->password);
- }
- }
- server=test
- user=root
- pass=pass
- dbname=mydb
- class A {
- public $config;
- public function __construct() {
- $this->config = parse_ini_file('config.ini', true);
- }
- public function sql {
- $connections = mysql_connect($this->config['server'], $this->config['user'],$this->config['password']) or die ('Unabale to connect to the database');
- mysql_select_db($this->config['dbase']) or die ('Unable to select database!');
- return;
- }
- }
- function connect()
- {
- include ('config.php');
- $connections = mysql_connect($server, $user,$password) or die ('Unabale to connect to the database');
- mysql_select_db($dbase) or die ('Unable to select database!');
- return;
- }
- config.php
- define('SERVER',$server);
- define('USER',$user);
- define('PASSWORD',$password);
- define('DBASE',$dbase);
- ----------class----------
- <?php
- include ('config.php');
- error_reporting($__error_reporting_level);
- class sql
- {
- protected $server=SERVER;
- protected $user=USER;
- protected $password=PASSWORD;
- protected $dbase=DBASE;
- private function connect()
- {
- $connections = mysql_connect($this->server, $this->user,$this->password) or die ('Unabale to connect to the database');
- mysql_select_db($this->dbase) or die ('Unable to select database!');
- return;
- }
- ........
- ........
Add Comment
Please, Sign In to add comment