I am trying to build a function to query and it is giving me a Resource id #6
when I echoed the function, it gave me no error.
This is the function:
$connect = mysql_connect($dbinfo['location'], $dbinfo['user'], $dbinfo['pass'], $dbinfo['database']);
$select_db = mysql_select_db($dbinfo['database']) or die('could not connect to database ' . $dbinfo['database']);
if(!$connect)
{
die('could not connect to database: ' . mysql_error());
}
function query($sql)
{
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
return $result;
}
Here is how I called it:
<?php
require_once '_core/init.php';
echo query("SELECT username FROM users WHERE user_id = 1");
?>
Any help would be much appreciated. Thanks!