Passing A Value By Reference Between Scripts - How?
Posted: Thu May 01, 2003 7:37 am
I've used a variation of a couple of scripts floating around the net in order to display images stored in a MySql database. Leaving out the database connections, opens, etc., the calling script queries for a set of database records for the page, then uses an <img scr> tag for display which calls another php routine, as in:
$query = "SELECT thumbid, annotation, filename FROM thumbs
WHERE pageno = 1";
(!($result = @ mysql_query ($query, $dbh)));
?>
<h1>Image Database</h1>
<?php
if ($row = @ mysql_fetch_array($result))
{
?>
<center><table BORDER=2 COLS=1 WIDTH="80%" >
<?php
do
{
?>
<tr>
<td><?php echo "{$row["filename"]}";?></td>
<td><?php echo "<img src=\"getdbblob.php?file={$row["thumbid"]}\">";?></td>
</tr>
<?php
} while ($row = @ mysql_fetch_array($result));
?>
</table>
<?php
} // if mysql_fetch_array()
?>
</table></center>
</body>
</html>
Now, the script, getdbblob.php also does a query to get a record on the passed record id.
<?php
ob_start(); // turn output buffering on
$query = "SELECT thumbnail FROM thumbs
WHERE thumbid = $file";
(!($result = @ mysql_query ($query, $dbh)));
$data = @mysql_fetch_array($result);
$image = $data["thumbnail"];
header("Content-Type: image/jpeg");
echo $image;
ob_end_flush();
?>
Now this seems wasteful because every image has to be queried out of the DB when it already exists in the calling script. I'd like to just pass the image data to the getblobdb script so there would be no need for a second query, but passing by value will make a copy of what _could_ be a large amount of data.
I need the format/syntax for passing & retrieving by reference.
TIA
$query = "SELECT thumbid, annotation, filename FROM thumbs
WHERE pageno = 1";
(!($result = @ mysql_query ($query, $dbh)));
?>
<h1>Image Database</h1>
<?php
if ($row = @ mysql_fetch_array($result))
{
?>
<center><table BORDER=2 COLS=1 WIDTH="80%" >
<?php
do
{
?>
<tr>
<td><?php echo "{$row["filename"]}";?></td>
<td><?php echo "<img src=\"getdbblob.php?file={$row["thumbid"]}\">";?></td>
</tr>
<?php
} while ($row = @ mysql_fetch_array($result));
?>
</table>
<?php
} // if mysql_fetch_array()
?>
</table></center>
</body>
</html>
Now, the script, getdbblob.php also does a query to get a record on the passed record id.
<?php
ob_start(); // turn output buffering on
$query = "SELECT thumbnail FROM thumbs
WHERE thumbid = $file";
(!($result = @ mysql_query ($query, $dbh)));
$data = @mysql_fetch_array($result);
$image = $data["thumbnail"];
header("Content-Type: image/jpeg");
echo $image;
ob_end_flush();
?>
Now this seems wasteful because every image has to be queried out of the DB when it already exists in the calling script. I'd like to just pass the image data to the getblobdb script so there would be no need for a second query, but passing by value will make a copy of what _could_ be a large amount of data.
I need the format/syntax for passing & retrieving by reference.
TIA