Hi, I want to create a reusable function to get information from a database rather then rewriting a query over and over, to make it a bit more complex (I think), I want it to be able to use the same function to get data from any table within the given database (hope that makes sense!). I’m fairly new to php so be gentle!
here is the function code I have so far in a file called functions.php:
<?
require_once 'config.php';//the db connect file
function db_query($table, $extras){
$query = "SELECT * FROM $table $extras";
$result = mysql_query($query) or die('Error: '.mysql_error());
}
?>
then I’m trying to use it in a separate file:
<?php
include 'build/functions.php';
$table = "stuf***e";
$extras = "ORDER BY id DESC";
db_query($table, $extras);
echo $result;
?>
When I try and use $result, it tells me it is undefined??
Any help would be greatly appreciated.
THanks