Jump to content

help with db connection


aruns

Recommended Posts

Hai guys,

class connection {

var $server;
var $user;
var $pass; 
var $db;
var $con;

function connection($server, $user, $pass, $db)
{
	$this->server = $server;
	$this->user = $user;
	$this->pass = $pass;
	$this->db = $db;
}

function connect($sql)
{
	$this->con = mysql_connect($this->server, $this->user, $this->pass);

	mysql_select_db($this->db, $this->con);

	$que = @mysql_query($sql);

	settype ($que, "null");

	mysql_close($this->con);
	}
}

$server = "localhost";

$user = "root";

$pass = "fairy";

$db = "up";

$dbconnect = new connection($server, $user, $pass, $db);

$que = $dbconnect->connect("select * from load");

$res = mysql_fetch_array($que);

echo $res['name'];

 

this cannot working

 

Arun

Link to comment
https://forums.phpfreaks.com/topic/96275-help-with-db-connection/
Share on other sites


define('CFG_SQLHOST','host');
define('CFG_SQLLOGIN','login');
define('CFG_SQLPASS','pass');
define('CFG_SQLDB','db');
define('CFG_SQLPORT','port');

class DB_MYSQL {
  	var $LinkID = false;
   	var $QueryID = false;
   	var $Record = array();
   	var $Row;
   	var $Errno = 0;
var $Error = '';

   	function connect() {
      	if(!$this->LinkID) {
         	$this->LinkID = mysql_connect(CFG_SQLHOST.':'.CFG_SQLPORT,CFG_SQLLOGIN,CFG_SQLPASS);
         	if (!$this->LinkID) {
            	$this->halt('Connection failed (host:'.CFG_SQLHOST.':'.CFG_SQLPORT.' Login:'.CFG_SQLLOGIN.')');
        	}
      	}
   }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.