Why is MySQL Connection Closing After ?>
Posted: Fri Oct 16, 2009 2:19 pm
The first query works fine and data is returned.
The second query fails. If I reopen the mysql connection it works. Why is my connection being closed? Does the mysql connection close automatically when it hits the php closing tag? It's not a big deal, it just seems like I should be able to leave the connection to mysql open until the end of the php document.
The second query fails. If I reopen the mysql connection it works. Why is my connection being closed? Does the mysql connection close automatically when it hits the php closing tag? It's not a big deal, it just seems like I should be able to leave the connection to mysql open until the end of the php document.
Code: Select all
<html>
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost", "name", "password") or die(mysql_error());
mysql_select_db("intf", $con);
$sql = "select o.id, ok.kind, ol.label ";
$sql .= "from objs o ";
$sql .= "inner join objkinds ok ";
$sql .= "on o.kind=ok.id ";
$sql .= "left join objlabels ol ";
$sql .= "on o.v1=ol.id ";
$sql .= "where o.loc=$loc ";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo "<a href='objs2.php?id=$row[id]'>$row[id] - $row[kind] - $row[label]</a><br />";
}
?>
<p>
<form name="input" action="html_form_submit.asp" method="post">
type: <select name="sections">
<?
$sql = "select id, kind ";
$sql .= "from objkinds ";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo "<option valye=$row[id]>$row[kind]</option>";
}
mysql_close($con);
?>
</select>
label: <input type="text" name="label">
<input type="submit" value="Submit" />
</form>
</p>
</body>
</html>