Hello all,
im having some problem, i have a function call dbconn which i run after my session. i can successfully connect to the database and run the mysql statement outside of the function with no problems. However, when i put it in the function and return it, nothing happens. Example:
index.php
<?php
include_once 'includes/db_connect.php';
sec_session_start();
dbconn();
echo $rows["username"];
?>
db_connect.php
<?php
function dbconn($autoclean = false) {
if (!@mysql_connect(HOST, USER, PASSWORD)) {
switch (mysql_errno()) {
case 1040:
case 2002:
if ($_SERVER['REQUEST_METHOD'] == "GET")
die("<html><head><meta http-equiv='refresh' content=\"5 $_SERVER[REQUEST_URI]\"></head><body><table border='0' width='100%' height='100%'><tr><td><h3 align='center'>The server load is very high at the moment. Retrying, please wait...</h3></td></tr></table></body></html>");
else
die("Too many users. Please press the Refresh button in your browser to retry.");
default:
die("[" . mysql_errno() . "] dbconn: mysql_connect: " . mysql_error());
}
}
mysql_select_db("sh") or die(mysql_error());
mysql_set_charset('utf8');
$res = mysql_query("SELECT * FROM users WHERE id = ".htmlentities($_SESSION["id"])." AND enabled='yes' AND status = 'confirmed'");// or die(mysql_error());
$rows = mysql_fetch_assoc($res);
if (!$rows)
return $rows;
if ($autoclean)
register_shutdown_function("autoclean");
}
?>
if i echo a statement after return $rows, it echos. What am i doing wrong?