Re: newbie : how to access functions in seperate files???
| From: | Aaron Moore | Date: | Mon, 03 Sep 2001 06:19:36 +0000 |
| Subject: | Re: newbie : how to access functions in seperate files??? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-65704@lists.php.net to get a copy of this message | ||
Heres what I have so far. I've put all the fiels into one folder, and i know
the paths are correct since they don't give an include error. The error
resides in line 6 of test.php where i try to call a function which is in
function.php
the test.php file :
_______________________________________
<?php
require("functions.php");
require("config.php");
require("init.php");
$id = get_total("news");
$row = get_newspost($id);
$row["news_subject"]
?>
_______________________________________
function.php file :
_______________________________________
<php
// Returns and array to the fields of a newspost of $id
function get_newspost($id) {
$sql = "SELECT news_id, news_subject, news_news, news_date, news_image,
news_link, news_link_style FROM news WHERE news_id = '$id'";
if(!$result = mysql_query($sql, $db))
return("ERROR");
if(!$row = mysql_fetch_array($result))
return("ERROR");
return $row;
}
// Returns the total number of $type posts
function get_total($type) {
$sql = "SELECT count(*) AS total FROM $type";
if(!$result = mysql_query($sql, $db))
return("ERROR");
if(!$myrow = mysql_fetch_array($result))
return("0");
return($myrow[total]);
}
?>
_______________________________________
init.php file
_______________________________________
<?php
global $db;
// Connect to database and create $db tag
if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpasswd"))
die('<font size=+1>An Error Occured</font><hr>phpBB was unable to connect
to the database. <BR>Please check $dbhost, $dbuser, and $dbpasswd in
config.php.');
if(!@mysql_select_db("$dbname",$db))
die("<font size=+1>An Error Occured</font><hr>phpBB was unable to find the
database <b>$dbname</b> on your MySQL server. <br>Please make sure you ran
the phpBB installation script.");
?>
_______________________________________
config.php file (info replaced with ### for security sorry):
_______________________________________
<?php
// Database Information
$dbname = "######";
$dbhost = "######";
$dbuser = "######";
$dbpasswd = "######";
?>
_______________________________________