Posts: 1,832
Location: Somewhere else entirely
|
Yes it does look like a new connection is made every time....
If it were me, I'd make $conn into a member variable of the class:
PHP Code:
<?php
class db_sql {
var $dbserver="";
var $user="";
var $pass="";
var $name="";
var $array=array();
var $conn;
function connect() {
$this->conn=mysql_connect($this->dbserver,$this->user,$this->pass) or $this->db_die();
}
function db_query($query) {
$get=mysql_db_query($this->name,$query,$this->conn) or $this->db_die();
list($result)=mysql_fetch_row($get);
return $result;
}
function num_vals($query) {
$get=mysql_db_query($this->name,$query,$this->conn) or $this->db_die();
$this->array=array();
while($row=mysql_fetch_array($get)) {
$this->array[]=$row[0];
}
return $this->array;
}
function mul_vals($query) {
$get=mysql_db_query($this->name,$query,$this->conn) or $this->db_die();
$this->array=array();
$this->array=mysql_fetch_array($get);
return $this->array;
}
function ins_vals($query) {
$do=mysql_db_query($this->name,$query,$this->conn) or $this->db_die();
}
function db_die() {
die("Mysql error");
}
}
?>
It's also inefficient in that if you want to know the number of rows returned for a query, it re-runs the query!
Beware, the only OO type coding I've done any great amount of is JAVA and C++, so the above code may have some problem that I've missed.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Please login or register to view this content. Registration is FREE (aka MSN handwriting for forums)
|