note 47572 deleted from ref.array by aidan
| From: | aidan@php.net | Date: | Sun, 09 Oct 2005 09:14:23 +0000 |
| Subject: | note 47572 deleted from ref.array by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96734@lists.php.net to get a copy of this message | ||
Note Submitter: sd dot admin at cosmosgaming dot com
----
The functions above depict how functions can be used when arrays need to be put into a function
which would have one result.
I would like to clarify on the fact that only one result or output can exist for a function. This
conspicuously is a restatement of an inference from the definition of a function.
To handle a MySQL connnection function, it is thus obvious that both connection and database
retrieval cannot be done through one function, which was one of my goals. My recommendation,
however, for dealing with this type of work, is to simply have one function to connect, which would
look like this:
function mysqldatabaseconnection($host, $hostuser, $hostpass, $db, $error)
{
$link = mysql_connect($host, $hostuser, $hostpass) or die($error . "Connection failed:
" . mysql_error());
// echo "Connected successfully";
mysql_select_db($db) or die($error . "Selection of database failed: " . mysql_error());
// $dbconnectset=array(dblink => $link, result => $result); As seen here the retrieval was
done here too, but that was cut out for time-saving
return $link;
}
To connect from inside the HTML page, use this:
$link = mysqldatabaseconnection($host, $hostuser, $hostpass, $db, $error);
Afterwards the retrieval of data can be pursued with techniques as seen on http://us2.php.net/manual/en/function.mysql-fetch-array.php.
Finally, and of some high degree of significance, the connection can be closed, since the link
exists, with:
mysql_close($link);