[HELP] PHP Coding [HELP]

Status
Not open for further replies.

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
Hey,

As some of you may know, im developing ParaCMS. Ive come across a small problem.
I have a code:
Code:
mysql_connect($CONFIG['mysql']['hostname'],$CONFIG['mysql']['username'],$CONFIG['mysql']['password']) or die("Could not connect to server, error: ".mysql_error());
mysql_select_db($CONFIG['mysql']['database']) or die("Could not connect to database, error: ".mysql_error());
and I want to put it in a global.php document. Rather than having it in my config.php. I have tried to use include 'config.php' in my global.php page, but its failing. CODE:

Config:
Code:
<?php

/*=======================================================================
| Paranormal CMS - A Habbo hotel Content Managment System
| #######################################################################
| Copyright 2012 Josh 'JoshuaLuke or FreddyZoom' All Rights Reserved
| This is a free CMS: You may not distribute this under ANY condition
| without the owners permission. Failure to do so may result in
| legal action.
| #######################################################################
| This program is distributed in the hope that it will be useful and
| efficient for your needs.
\======================================================================*/

// Below is the configuration for MySQL. Please fill all of it out correctly in order for the website to function

$CONFIG['mysql']['hostname'] = 'localhost'; // MySQL Host

$CONFIG['mysql']['username'] = 'root'; // MySQL Username

$CONFIG['mysql']['password'] = 'hello12'; // MySQL Password

$CONFIG['mysql']['database'] = 'phx'; // MySQL Database
?>

Global:
Code:
<?php
include_once 'config.php';

mysql_connect($CONFIG['mysql']['hostname'],$CONFIG['mysql']['username'],$CONFIG['mysql']['password']) or die("Could not connect to server, error: ".mysql_error());
mysql_select_db($CONFIG['mysql']['database']) or die("Could not connect to database, error: ".mysql_error());


?>

If you can sort my problams, please tell me :)
 

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
Updated:

Config:
Code:
<?php

/*=======================================================================
| Paranormal CMS - A Habbo hotel Content Managment System
| #######################################################################
| Copyright 2012 Josh 'JoshuaLuke or FreddyZoom' All Rights Reserved
| This is a free CMS: You may not distribute this under ANY condition
| without the owners permission. Failure to do so may result in
| legal action.
| #######################################################################
| This program is distributed in the hope that it will be useful and
| efficient for your needs.
\======================================================================*/

global $config;

// Below is the configuration for MySQL. Please fill all of it out correctly in order for the website to function

$CONFIG['mysql']['hostname'] = 'localhost'; // MySQL Host

$CONFIG['mysql']['username'] = 'root'; // MySQL Username

$CONFIG['mysql']['password'] = 'hello12'; // MySQL Password

$CONFIG['mysql']['database'] = 'phx'; // MySQL Database

Global
Code:
<?php

require_once('config.php');

function connect() {
mysql_connect($CONFIG['mysql']['hostname'],$CONFIG['mysql']['username'],$CONFIG['mysql']['password']) or die("Could not connect to server, error: ".mysql_error());
mysql_select_db($CONFIG['mysql']['database']) or die("Could not connect to database, error: ".mysql_error());
}


?>

Still isnt working
 

brsy

nah mang
May 12, 2011
1,530
272
Use this:

Plus, where you select the database, you are suppose to put the connection, like I did below.

PHP:
class engine {
 
    public function __construct() {
        global $config;
   
            $con = mysql_connect($config['db']['host'], $config['db']['user'], $config['db']['password']) or die("y u no put right password");
            mysql_select_db($config['db']['database'], $con) or die("wrong database");
    }
}
 

Adil

DevBest CEO
May 28, 2011
1,278
716
Updated:

Config:
Code:
<?php

/*=======================================================================
| Paranormal CMS - A Habbo hotel Content Managment System
| #######################################################################
| Copyright 2012 Josh 'JoshuaLuke or FreddyZoom' All Rights Reserved
| This is a free CMS: You may not distribute this under ANY condition
| without the owners permission. Failure to do so may result in
| legal action.
| #######################################################################
| This program is distributed in the hope that it will be useful and
| efficient for your needs.
\======================================================================*/

global $config;

// Below is the configuration for MySQL. Please fill all of it out correctly in order for the website to function

$CONFIG['mysql']['hostname'] = 'localhost'; // MySQL Host

$CONFIG['mysql']['username'] = 'root'; // MySQL Username

$CONFIG['mysql']['password'] = 'hello12'; // MySQL Password

$CONFIG['mysql']['database'] = 'phx'; // MySQL Database

Global
Code:
<?php

require_once('config.php');

function connect() {
mysql_connect($CONFIG['mysql']['hostname'],$CONFIG['mysql']['username'],$CONFIG['mysql']['password']) or die("Could not connect to server, error: ".mysql_error());
mysql_select_db($CONFIG['mysql']['database']) or die("Could not connect to database, error: ".mysql_error());
}


?>

Still isnt working
Fucking epic facepalm.
Change $config to $CONFIG (your config array)
facepalm.jpg
 

Adil

DevBest CEO
May 28, 2011
1,278
716
Oh fucking Hell.
WHY DO YOU HAVE GLOBAL $config in your config file?
Declare the fucking config array.
$CONFIG=array();
 

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
Read my reply above..

Ive tried using it, dosent work either:

CONFIG:
Code:
<?php
 
/*=======================================================================
| Paranormal CMS - A Habbo hotel Content Managment System
| #######################################################################
| Copyright 2012 Josh 'JoshuaLuke or FreddyZoom' All Rights Reserved
| This is a free CMS: You may not distribute this under ANY condition
| without the owners permission. Failure to do so may result in
| legal action.
| #######################################################################
| This program is distributed in the hope that it will be useful and
| efficient for your needs.
\======================================================================*/
 
global $CONFIG;
 
// Below is the configuration for MySQL. Please fill all of it out correctly in order for the website to function
 
$CONFIG['mysql']['hostname'] = 'localhost'; // MySQL Host
 
$CONFIG['mysql']['username'] = 'root'; // MySQL Username
 
$CONFIG['mysql']['password'] = 'hello12'; // MySQL Password
 
$CONFIG['mysql']['database'] = 'phx'; // MySQL Database
?>

GLOBAL:
Code:
<?php
 
class engine {
 
    public function __construct() {
        global $CONFIG;
     
            $con = mysql_connect($CONFIG['db']['host'], $CONFIG['db']['user'], $CONFIG['db']['password']) or die("y u no put right password");
            mysql_select_db($CONFIG['db']['database'], $con) or die("wrong database");
    }
}
 
?>

Just to clarify, I havent got'ny class.core, class.engine etc yet


Isnt working adil :l
 

brsy

nah mang
May 12, 2011
1,530
272
Ive tried using it, dosent work either:

CONFIG:
Code:
<?php
 
/*=======================================================================
| Paranormal CMS - A Habbo hotel Content Managment System
| #######################################################################
| Copyright 2012 Josh 'JoshuaLuke or FreddyZoom' All Rights Reserved
| This is a free CMS: You may not distribute this under ANY condition
| without the owners permission. Failure to do so may result in
| legal action.
| #######################################################################
| This program is distributed in the hope that it will be useful and
| efficient for your needs.
\======================================================================*/
 
global $CONFIG;
 
// Below is the configuration for MySQL. Please fill all of it out correctly in order for the website to function
 
$CONFIG['mysql']['hostname'] = 'localhost'; // MySQL Host
 
$CONFIG['mysql']['username'] = 'root'; // MySQL Username
 
$CONFIG['mysql']['password'] = 'hello12'; // MySQL Password
 
$CONFIG['mysql']['database'] = 'phx'; // MySQL Database
?>

GLOBAL:
Code:
<?php
 
class engine {
 
    public function __construct() {
        global $CONFIG;
   
            $con = mysql_connect($CONFIG['db']['host'], $CONFIG['db']['user'], $CONFIG['db']['password']) or die("y u no put right password");
            mysql_select_db($CONFIG['db']['database'], $con) or die("wrong database");
    }
}
 
?>

Just to clarify, I havent got'ny class.core, class.engine etc yet


Isnt working adil :l
OMFG. You have to fucking use what I gave you, then simply edit all the variables to the one in your config...
 

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
OMFG. You have to fucking use what I gave you, then simply edit all the variables to the one in your config...
I already did, after posting:

GLOBAL:
Code:
<?php

class engine {
 
    public function __construct() {
        global $CONFIG;
        $CONFIG = array();
       
            $CONFIG = mysql_connect($CONFIG['mysql']['hostname'], $CONFIG['mysql']['username'], $CONFIG['mysql']['password']) or die("y u no put right password");
            mysql_select_db($CONFIG['mysql']['database'], $CONFIG) or die("wrong database");
    }
}

?>

CONFIG:
Code:
<?php

/*=======================================================================
| Paranormal CMS - A Habbo hotel Content Managment System
| #######################################################################
| Copyright 2012 Josh 'JoshuaLuke or FreddyZoom' All Rights Reserved
| This is a free CMS: You may not distribute this under ANY condition
| without the owners permission. Failure to do so may result in
| legal action.
| #######################################################################
| This program is distributed in the hope that it will be useful and
| efficient for your needs.
\======================================================================*/

$CONFIG = array();

// Below is the configuration for MySQL. Please fill all of it out correctly in order for the website to function

$CONFIG['mysql']['hostname'] = 'localhost'; // MySQL Host

$CONFIG['mysql']['username'] = 'root'; // MySQL Username

$CONFIG['mysql']['password'] = 'hello12'; // MySQL Password

$CONFIG['mysql']['database'] = 'phx'; // MySQL Database
?>

Cant you just correct them for me :l
 

brsy

nah mang
May 12, 2011
1,530
272
PHP:
        $config['db']['host'] = 'localhost'; // MySQL Host
 
$config['db']['user'] = 'root'; // MySQL Username
 
$config['db']['password'] = 'hello12'; // MySQL Password
 
$config['db']['database'] = 'phx'; // MySQL Database

PHP:
            $con = mysql_connect($config['db']['host'], $config['db']['user'], $config['db']['password']) or die("y u no put right password");
            mysql_select_db($config['db']['database'], $con) or die("wrong database");
 
Status
Not open for further replies.

Users who are viewing this thread

Top