note 47572 added to ref.array
| From: | sd dot admin at cosmosgaming dot com | Date: | Sat, 20 Nov 2004 22:59:43 +0000 |
| Subject: | note 47572 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80815@lists.php.net to get a copy of this message | ||
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);
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47572
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47572&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47572&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47572&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47572&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47572&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47572&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47572&report=yes
Search -- http://master.php.net/manage/user-notes.php