Page 1 of 1

Problem closing mysql connection (Solved)

Posted: Wed Sep 05, 2007 9:41 am
by Art-art
Hi,

In one of my User Defined Tags I'm trying to include an external database query in order to produce a listing.

It looks like:

Code: Select all

//User Defined Tag: Listing

require ('connection.php');

$link= mysql_connect($host,$user,$password)
	or die ("couldn't connect to server");
  
$db = mysql_select_db($database,$link)
	or die ("Couldn't select database");

$query = "SELECT * FROM tbl_x LEFT JOIN tbl_y
	ON a=b
	ORDER BY c, d"; 

$result = mysql_query($query)
	or die ("Couldn't execute query.");

	while ($row = mysql_fetch_array($result))
	{
		echo "<ul>";
			extract($row);
			echo "
				<li>
					<a href='http://domain.com/blahblah.php
					?page=e&f=$g'>
					$c, $d </a>
				</li>
			</p>";
		echo "</ul>";
	}

mysql_close($link);
This lists everything I need however something goes wrong at the footer of the page. This shows:
string(61) "Smarty error: unable to read resource: "globalcontent:footer"" string(61) "Smarty error: unable to read resource: "globalcontent:footer""
and shows no proper footer.

Just removing the last line of the User Defined Tag

Code: Select all

mysql_close($link);
seems to solve the problem. In my opinion however I need to close the connection to comply with the recommended mysql code. Renaming the link didn't make any difference.

Re: Problem closing mysql connection

Posted: Wed Sep 05, 2007 10:13 am
by cyberman
It looks like mysql_close() closes all connections.

Have you tried to access database via adodb?

http://forum.cmsmadesimple.org/index.ph ... 863.0.html

Re: Problem closing mysql connection

Posted: Wed Sep 05, 2007 10:22 am
by alby
Arthur wrote:
$link= mysql_connect($host,$user,$password, true)
or die ("couldn't connect to server");
 

mysql_close($link);
You close mysql connection. Try to add the red part (open a new mysql connection)

Alby

Re: Problem closing mysql connection

Posted: Wed Sep 05, 2007 10:36 am
by Art-art
Hi Cyberman and Alby,

Thanks for your quick answers. I was digging into your suggestion, Cyberman, and then the quick resolution of Alby came in.
The latter seems to have solved the problem.
The next step will be a 2nd database lookup on the same page. Let’s see if this still works.

Both thanks again.

Re: Problem closing mysql connection (Solved)

Posted: Wed Sep 05, 2007 12:12 pm
by Art-art
Update:

I now included 2 queries in one page and this worked as well !