I create a object, but then I want to destroy it, like in the C language.
After this if I create an object let's say for connection to a mysql server I can automaticly init the conection in constructor. But after that I want to disconect, I have a destructor?? because I didn't find it in documentation. I read about unset but when I call it will automaticly disconect the conection to mysql????
I made a object, for mysql connection. It's working fine but at opendbconnection() function when I select the database I have to put it "by hand" the name of the database:
It's working
mysql_select_db('a4mula1');
It's not working
mysql_select_db("$db");
Did I made something wrong???
Here is the code I use.
<?php
$host="HOST";
$db="DATABASE";
$user="USER";
$pass="PASSWORD";
class mysql {
var $init;
var $sql;
var $qry;
var $nrrows;
var $nrfields;
var $result;
function mysql() {
$this->open();
}
function open() {
GLOBAL $host,$db,$user,$pass;
$this->$init= mysql_connect("$host:3306", "$user","$pass")
or die ("<BR><BR><B>Can't conect to server</B><BR><BR>");
mysql_select_db('a4mula1')
or die ("<BR><BR><B>I don't find database $db</B><BR><BR>");
}
function close() {
mysql_close($this->init);
}
function setsql($req_sql) {
$this->sql = $req_sql;
}
function query() {
$this->qry = mysql_query ($this->sql)
or die ("<BR><BR><B>Something wrong with the query. Please check it or try again</B><BR>$this->sql<BR><
BR>");
}
function getnrfields() {
$this->nrfields= mysql_num_fields($this->qry);
}
function getnrrows() {
$this->nrrows= mysql_num_rows($this->qry);
}
function getresult() {
if ($this->result=mysql_fetch_row($this->qry)) {
return TRUE;
} else {
return FALSE;
}
}
}
?>
King regards,
iugin
<!-- m --><a class="postlink" href="http://www.4mula1.f2s.com">http://www.4mula1.f2s.com</a><!-- m -->
After this if I create an object let's say for connection to a mysql server I can automaticly init the conection in constructor. But after that I want to disconect, I have a destructor?? because I didn't find it in documentation. I read about unset but when I call it will automaticly disconect the conection to mysql????
I made a object, for mysql connection. It's working fine but at opendbconnection() function when I select the database I have to put it "by hand" the name of the database:
It's working
mysql_select_db('a4mula1');
It's not working
mysql_select_db("$db");
Did I made something wrong???
Here is the code I use.
<?php
$host="HOST";
$db="DATABASE";
$user="USER";
$pass="PASSWORD";
class mysql {
var $init;
var $sql;
var $qry;
var $nrrows;
var $nrfields;
var $result;
function mysql() {
$this->open();
}
function open() {
GLOBAL $host,$db,$user,$pass;
$this->$init= mysql_connect("$host:3306", "$user","$pass")
or die ("<BR><BR><B>Can't conect to server</B><BR><BR>");
mysql_select_db('a4mula1')
or die ("<BR><BR><B>I don't find database $db</B><BR><BR>");
}
function close() {
mysql_close($this->init);
}
function setsql($req_sql) {
$this->sql = $req_sql;
}
function query() {
$this->qry = mysql_query ($this->sql)
or die ("<BR><BR><B>Something wrong with the query. Please check it or try again</B><BR>$this->sql<BR><
BR>");
}
function getnrfields() {
$this->nrfields= mysql_num_fields($this->qry);
}
function getnrrows() {
$this->nrrows= mysql_num_rows($this->qry);
}
function getresult() {
if ($this->result=mysql_fetch_row($this->qry)) {
return TRUE;
} else {
return FALSE;
}
}
}
?>
King regards,
iugin
<!-- m --><a class="postlink" href="http://www.4mula1.f2s.com">http://www.4mula1.f2s.com</a><!-- m -->