Problem closing mysql connection (Solved)

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
Art-art

Problem closing mysql connection (Solved)

Post 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.
Last edited by Art-art on Wed Sep 05, 2007 10:47 am, edited 1 time in total.
cyberman

Re: Problem closing mysql connection

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

Re: Problem closing mysql connection

Post 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
Art-art

Re: Problem closing mysql connection

Post 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.
Art-art

Re: Problem closing mysql connection (Solved)

Post by Art-art »

Update:

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

Return to “CMSMS Core”