include() Problem, PHP/MySQL
04-29-2005, 09:47 PM
|
include() Problem, PHP/MySQL
|
Posts: 84
|
I have 2 files in a folder named setup, the setup.php and config.php... the setup script should create the tables for the databse my site is using... but the include() part in setup.php doesnt seem to import the config.php right..... as i also included
Code:
echo "Unable to connect database - ".$hostname."-".$dbase_user."-".$dbase_pass;
to know if the config file was properly included, but the values didnt show... any of you know what i did wrong here?
config.php
Code:
<?php
//for database stuffs
$dbasename = "DataX";
$dbase_user = "jake";
$dbase_pass = "1234pass";
$site_prefix = "great_";
$hostname = "56G8.yogo.net";
//for news in main page
$site_dbasename = "DataX";
$num_news = 10;
$num_recent_news = 6;
$num_world_news = 6;
$content_size = 300;
//for news archives section
$num_archives = 3;
$num_archives_pages = 4;
$news_per_page = ( $num_archives + $num_archives_pages ) + 1;
?>
setup.php
Code:
<?php
include( "config.php" );
function query( $query )
{
$func_query = $query;
return mysql_query( $func_query );
}
function db_connect( $hostname, $username, $password )
{
return mysql_connect( $hostname, $username, $password );
}
function db_select( $database_name )
{
mysql_select_db( $database_name );
}
function db_close( $database )
{
mysql_close( $database );
}
$db = db_connect( $hostname, $dbase_user, $dbase_pass);
if( !$db )
echo "Unable to connect database - ".$hostname."-".$dbase_user."-".$dbase_pass;
else
{
db_select( "db122612119" );
if( !query("CREATE TABLE `".$site_prefix."admins` (
`aid` bigint(20) NOT NULL auto_increment,
`username` text NOT NULL,
`password` text NOT NULL,
`token` text NOT NULL,
PRIMARY KEY (`aid`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;") )
echo "Unable to create table ADMINS";
if( !query( "INSERT INTO `".$site_prefix."admin` VALUES (1, 'admin', '123pass', '7835408415b24599dbc863033960fd8d');" ) )
echo "Unable to insert ADMINS";
if( !query( "CREATE TABLE `".$site_prefix."news` (
`nid` bigint(20) NOT NULL auto_increment,
`news_title` text NOT NULL,
`news_content` text NOT NULL,
`news_writer` text NOT NULL,
`news_url` text NOT NULL,
`time_posted` bigint(20) NOT NULL default '0',
`news_source` text NOT NULL,
`news_source_url` text NOT NULL,
KEY `nid` (`nid`)
) TYPE=MyISAM AUTO_INCREMENT=36 ;" ) )
echo "Unable to insert ADMINS";
if( !query( "CREATE TABLE `".$site_prefix."bom` (
`bid` bigint(20) NOT NULL auto_increment,
`boxer` text NOT NULL,
`content` text NOT NULL,
`monthyear` text NOT NULL,
KEY `bid` (`bid`)
) TYPE=MyISAM AUTO_INCREMENT=30 ;" ) )
echo "Unable to Create Table BOM";
if( !query( "CREATE TABLE `".$site_prefix."topten` (
`rank` bigint(20) NOT NULL default '0',
`boxer` text NOT NULL,
`content` text NOT NULL,
`record` text NOT NULL,
KEY `rank` (`rank`)
) TYPE=MyISAM;" ) )
echo "Unable to Create Table TOPTEN";
if( !query( "CREATE TABLE `".$site_prefix."worldnews` (
`nid` bigint(20) NOT NULL auto_increment,
`news_title` text NOT NULL,
`news_writer` text NOT NULL,
`news_url` text NOT NULL,
`news_source` text NOT NULL,
`news_source_url` text NOT NULL,
KEY `nid` (`nid`)
) TYPE=MyISAM AUTO_INCREMENT=10 ;" ) )
echo "Unable to insert ADMINS";
}
?>
Last edited by ChancesAre; 04-29-2005 at 09:59 PM..
|
|
|
|
04-29-2005, 10:54 PM
|
|
Posts: 3,189
|
In order to use those included variables inside your functions you have to declare them as global inside your function, for instance.
PHP Code:
function db_connect( $hostname, $username, $password )
{
global $hostname, $username, $password;
return mysql_connect( $hostname, $username, $password );
}
|
|
|
|
04-30-2005, 12:29 AM
|
|
Posts: 84
|
Quote:
|
Originally Posted by cptnwinky
In order to use those included variables inside your functions you have to declare them as global inside your function, for instance.
PHP Code:
function db_connect( $hostname, $username, $password )
{
global $hostname, $username, $password;
return mysql_connect( $hostname, $username, $password );
}
|
i also have
Code:
echo "Unable to connect database - ".$hostname."-".$dbase_user."-".$dbase_pass;
outside a function i dont think it would need a global declaration coz its already global as far as i know and the values still dont show...
i have the same thing happening with my other files... i even got an undefined function error.. i have tested my scripts on my pc and it works fine but not on my host server... 
Last edited by ChancesAre; 04-30-2005 at 12:31 AM..
|
|
|
|
04-30-2005, 09:53 AM
|
|
Posts: 3,189
|
Did you even try what I suggested?
|
|
|
|
04-30-2005, 10:46 AM
|
|
Posts: 297
|
and why have you made functions for functions that already exist?
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill
Please visit my sites: Please login or register to view this content. Registration is FREE | Please login or register to view this content. Registration is FREE
|
|
|
|
04-30-2005, 11:44 PM
|
|
Posts: 84
|
im kinda not the best in php. i do more c/c++.. so im kinda noob so to speak.. i just want the functions easier to remember.. 
|
|
|
|
04-30-2005, 11:46 PM
|
|
Posts: 84
|
Quote:
|
Originally Posted by cptnwinky
Did you even try what I suggested?
|
not yet but ill later try, just to make sure its not it...
|
|
|
|
05-02-2005, 12:10 AM
|
|
Posts: 84
|
the global declaration didnt work just got a T_VARIABLE error....
what must be the problem here  this is killing me... i have phpbb forum installed and its working fine... and i noticed that its file path inside the include() has ".\" before the path/filename still didnt work so far when i put that in my includes..
any1 had this problem before?
|
|
|
|
05-02-2005, 12:44 AM
|
|
Posts: 84
|
lol just found the problem its when i upload my files the filename becomes uppercase... i just changed the filename in include() to uppercase and it worked..
peace all.. thnks for all the help peace 
|
|
|
|
|
« Reply to include() Problem, PHP/MySQL
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|