UDT mysql_close

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Golf Gti

UDT mysql_close

Post 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);
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: UDT mysql_close

Post 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.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: UDT mysql_close

Post 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
Post Reply

Return to “Developers Discussion”