FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » why can`t close mysql_connect?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
why can`t close mysql_connect? [message #179631] Thu, 15 November 2012 10:19 Go to next message
cngrit0305 is currently offline  cngrit0305
Messages: 4
Registered: November 2012
Karma: 0
Junior Member
hi,
I am a novice with php,today,I found can`t close mysql_connect.

I have a object "db_config.php"

class DbConfig{
private $db_url = 'localhost:3333';
private $db_user = 'root';
private $db_pwd = 'root';
private $db_name = 'xinxiwang';
function __get($property_name){
return $this->$property_name;
}

public function getConn(){
$link = mysql_connect($this->db_url,$this->db_user,$this->db_pwd)
or die("can not connect to Mysql server");
mysql_select_db($this->db_name,$link)
or die("can not found database " . $this->db_name );
return $link;
}
}

I will in a other php file include it "test.php"

require (db_config.php);

function fri_select($db,$pagenum,$counts){
$sql = "call friendlink_select($pagenum,$counts)";
$result = mysql_query($sql,$db);
mysql_close($db);
if($db){
echo "in function, con is alive;<br>";
}else{
echo "in function , con is dead";
}
if(isset($db)){
echo "in function,con is alive;<br>";
}else{
echo "in function , con is dead";
}
if(!empty($db)){
echo "in function,con is alive;<br>";
}else{
echo "in function , con is dead";
}
return $result;
}

$db = new DbConfig();
$dbs = $db->getConn();

$result = fri_select($dbs,1,6);
if($dbs){
echo "out function, con is alive;<br>";
}else{
echo "out function , con is dead";
}
if(isset($dbs)){
echo "out function,con is alive;<br>";
}else{
echo "out function , con is dead";
}
if(!empty($dbs)){
echo "out function,con is alive;<br>";
}else{
echo "out function , con is dead";
}

it will out put

in function,con is alive;
in function,con is alive;
in function,con is alive;
out function, con is alive;
out function,con is alive;
out function,con is alive;

why???I had close it in function!!!who can tell me??
thanks very much!!!
Re: why can`t close mysql_connect? [message #179636 is a reply to message #179631] Thu, 15 November 2012 12:46 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 11/15/2012 5:19 AM, cngrit0305(at)gmail(dot)com wrote:
> hi,
> I am a novice with php,today,I found can`t close mysql_connect.
>
> I have a object "db_config.php"
>
> class DbConfig{
> private $db_url = 'localhost:3333';
> private $db_user = 'root';
> private $db_pwd = 'root';
> private $db_name = 'xinxiwang';
> function __get($property_name){
> return $this->$property_name;
> }
>
> public function getConn(){
> $link = mysql_connect($this->db_url,$this->db_user,$this->db_pwd)
> or die("can not connect to Mysql server");
> mysql_select_db($this->db_name,$link)
> or die("can not found database " . $this->db_name );
> return $link;
> }
> }
>
> I will in a other php file include it "test.php"
>
> require (db_config.php);
>
> function fri_select($db,$pagenum,$counts){
> $sql = "call friendlink_select($pagenum,$counts)";
> $result = mysql_query($sql,$db);
> mysql_close($db);
> if($db){
> echo "in function, con is alive;<br>";
> }else{
> echo "in function , con is dead";
> }
> if(isset($db)){
> echo "in function,con is alive;<br>";
> }else{
> echo "in function , con is dead";
> }
> if(!empty($db)){
> echo "in function,con is alive;<br>";
> }else{
> echo "in function , con is dead";
> }
> return $result;
> }
>
> $db = new DbConfig();
> $dbs = $db->getConn();
>
> $result = fri_select($dbs,1,6);
> if($dbs){
> echo "out function, con is alive;<br>";
> }else{
> echo "out function , con is dead";
> }
> if(isset($dbs)){
> echo "out function,con is alive;<br>";
> }else{
> echo "out function , con is dead";
> }
> if(!empty($dbs)){
> echo "out function,con is alive;<br>";
> }else{
> echo "out function , con is dead";
> }
>
> it will out put
>
> in function,con is alive;
> in function,con is alive;
> in function,con is alive;
> out function, con is alive;
> out function,con is alive;
> out function,con is alive;
>
> why???I had close it in function!!!who can tell me??
> thanks very much!!!
>

$dbs is a resource, not a true/false value as to whether the connection
is alive or not. Even after closing the connection, the resource is
still there - but not the connection.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: why can`t close mysql_connect? [message #179659 is a reply to message #179636] Fri, 16 November 2012 17:30 Go to previous message
cngrit0305 is currently offline  cngrit0305
Messages: 4
Registered: November 2012
Karma: 0
Junior Member
在 2012年11月15日星期四UTC+1下午1时47分04秒,Jerry Stuckle写道:
> On 11/15/2012 5:19 AM, cngrit0305(at)gmail(dot)com wrote: > hi, > I am a novice with php,today,I found can`t close mysql_connect. > > I have a object "db_config.php" > > class DbConfig{ > private $db_url = 'localhost:3333'; > private $db_user = 'root'; > private $db_pwd = 'root'; > private $db_name = 'xinxiwang'; > function __get($property_name){ > return $this->$property_name; > } > > public function getConn(){ > $link = mysql_connect($this->db_url,$this->db_user,$this->db_pwd) > or die("can not connect to Mysql server"); > mysql_select_db($this->db_name,$link) > or die("can not found database " . $this->db_name ); > return $link; > } > } > > I will in a other php file include it "test.php" > > require (db_config.php); > > function fri_select($db,$pagenum,$counts){ > $sql = "call friendlink_select($pagenum,$counts)"; > $result = mysql_query($sql,$db); > mysql_close($db); > if($db){ > echo "in function, con is alive;<br>"; > }else{ > echo "in function , con is dead"; > } > if(isset($db)){ > echo "in function,con is alive;<br>"; > }else{ > echo "in function , con is dead"; > } > if(!empty($db)){ > echo "in function,con is alive;<br>"; > }else{ > echo "in function , con is dead"; > } > return $result; > } > > $db = new DbConfig(); > $dbs = $db->getConn(); > > $result = fri_select($dbs,1,6); > if($dbs){ > echo "out function, con is alive;<br>"; > }else{ > echo "out function , con is dead"; > } > if(isset($dbs)){ > echo "out function,con is alive;<br>"; > }else{ > echo "out function , con is dead"; > } > if(!empty($dbs)){ > echo "out function,con is alive;<br>"; > }else{ > echo "out function , con is dead"; > } > > it will out put > > in function,con is alive; > in function,con is alive; > in function,con is alive; > out function, con is alive; > out function,con is alive; > out function,con is alive; > > why???I had close it in function!!!who can tell me?? > thanks very much!!! > $dbs is a resource, not a true/false value as to whether the connection is alive or not. Even after closing the connection, the resource is still there - but not the connection. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex(at)attglobal(dot)net ==================

ok,thank you,i copy it.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: dns_get_record() with timeout?
Next Topic: How to add dynamic textbox (row) and save to database using PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 22:24:18 GMT 2024

Total time taken to generate the page: 0.02559 seconds