Page 1 of 1

UDT mysql_close

Posted: Fri Mar 06, 2009 3:14 am
by Golf Gti
I searched but did not find anything.

1. Do I have to use the mysql_close in a UDT? (it works without error when not supplied)
2. Will it leave the connection open? or is it closed with cmsms's tag

I have a UDT that opens a table on the same database that cmsms is on.
I get the Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource

Here is what I am using:

Code: Select all

$result = mysql_query("SELECT * FROM image_items WHERE id IN (590, 594, 591, 673, 574, 553, 568, 698)");
while($row = mysql_fetch_array($result))
  {
    echo "<a href=\"/images/catalog.php?id=" . $row["id"] . "\">
<img class=\"acc_img\" src=\"/images/" . $row["file_thumb"] . "\" border=0 alt=\"" . $row["title"] . "\">
</a>";
 echo '<table><tr>'; 
    { 
       $i++; 
      if ($i % 5 == 0) {
        echo '<td><span style="font-weight:bold;"> '. $row["title"] .'<br>'. $row["item"] .' <span style="color:#000099;"> $'. $row["price"] .' </span></span></td></tr><tr>'; 
    }else{ 
        echo '<td><span style="font-weight:bold;"> '. $row["title"] .'<br>'. $row["item"] .' <span style="color:#000099;"> $'. $row["price"] .' </span></span></td>'; 
      } 
    } 
    echo '</tr></table>'; 
  }
mysql_close($result);

Re: UDT mysql_close

Posted: Sun Mar 08, 2009 11:49 am
by plger
You trying to "close" the result of your query.
mysql_close() is to be used to close the connection :

Code: Select all

$dbcnx = mysql_connect( ... );
$result = mysql_query( ... );
// process the result
mysql_close($dbcnx);
In your example, you don't even open the connection, you use the cms', which is already open because I'd guess your configs are set to always on. So if the cms doesn't close it, why should you?

Btw, I would recommand using adodb:

Code: Select all

global $gCms;
$db = $gCms->GetDb();
$result = $db->Execute("yourquerytext");
while ($result && $row = $result->FetchRow()){
blablabla
}
Which would support non-mysql databases too.

Re: UDT mysql_close

Posted: Sun Mar 08, 2009 3:12 pm
by Nullig
If you do use the:

mysql_close ($my_dbconn); <- use whatever your connection is called

Make sure you add this after, to reopen the cmsms db connection:

adodb_connect();

Nullig