Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Author: Neil Masters[nim at cs.stir.ac.uk]
- This function attempts to be a generic db() application
- that handles any sql query's and returns results in
- an array.
- Example usage:
- foreach(dbArray("SELECT * FROM accounts","login,password") as $results)
- {
- $items = explode(",",$results);
- echo '<strong>username:</strong>' .
- $items[0] .
- ', <strong>password:</strong> ' .
- $items[1] . '<br />';
- }
- */
- function dbArray($query, $returnValues)
- {
- $returnValues = explode(",", $returnValues);
- $connect = mysql_connect("server_name","user_name","password") or die("Could not connect to database");
- $dbSelect = mysql_select_db("db_name", $connect) or die("Could not select table");
- $result = mysql_query($query);
- $i = 0;
- while($field = mysql_fetch_assoc($result))
- {
- $returnArray[$i] = $field[$returnValues[0]] . ',' . $field[$returnValues[1]];
- $i++;
- }
- return $returnArray;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement