bikerboy's Avatar
Go4Expert Member
this is just a test server im moving it somewer else after working
bikerboy's Avatar
Go4Expert Member
and thanks man any help would be great
pein87's Avatar
Ambitious contributor
ok I wrote a db class for you which includes a config page as well so you can edit that as you wish without having to edit the code in the class. Make sure that you also include the FB api script to the class script or the script your using for the functions because your making a call to an undefined class.

fb_con.config.php
PHP Code:
<?php
/*##################################\
# Database login and fb credentials #
#      include to use settings      #
#          by pein87 2010           #
\##################################*/

/* define mysql server sign credentials */
$DBCONN["server"] = "localhost";
$DBCONN["username"] = "root";
$DBCONN["password"] = "";
$DBCONN["port"] = "36";
$DBCONN["db_name"] = "";

$use_port "no";

/* define facebook credentials */

$FBCONN["api_key"] = "f78d0af4251f73febc77a65d31de1f01";
$FBCONN["secret"]  = "b210eda2b798ae37601dca47d1d0ed93";
$FBCONN["server_url"] = "http://immortalbattle.com/eminem/";
$FBCONN["application_url"] = "http://immortalbattle.com/eminem/";
$FBCONN["appId"] = "132402310129922";
$FBCONN["APP_NAME"] = "HIDDEN MESSAGES";

?>
class_fb-db.php
PHP Code:
<?php
/*###############################\
# core classes for fb connection #
#         by pein87 2010         #
\###############################*/

/* space reserved for defines */

// define('DEFINES_GO_HERE',true);

/* space reserved for defines */

/* include config */
include("fb_con.config.php");
/* include("fb_api.php);  you need to include the fb api file(s) to use there methods in the bewlo classes  */

class db // define db class and methods
{
    
static public function 
db_connecter()
{
    
$CONN "";// declare variable outside conditional scope
    
    
if($use_port == "no"// check if use port is set to no and connect to the db or return error message
    
{
        
$CONN = @mysql_connect($DBCONN["server"],$DBCONN["username"],$DBCONN["password"]) or die("could not connect to the database please check your settings in the config file");
        
    }
    else
    {
        
$CONN = @mysql_connect($DBCONN["server"] . ":" $DBCONN["port"],$DBCONN["username"],$DBCONN["password"]) or die("could not connect to the database please check your settings in the config file");
    }
    
$DB = @mysql_select_db($DBCONN["db_name"],$CONN) or die("Could not find the requested database please check your config settings.");
}
     
static public function 
sql_query($query// expects a sql not a return result
{
    
db_connecter();
    
$QUERY = @mysql_query($query) or die ("could not execute there query check your syntax");
    return 
$QUERY;    
}

static public function 
get_array($mysql_query,$return_type=NULL)// expects return result i.e a mysql_query use $dbConn->db->sql_query() here
{
    
db_connecter();
    
    
$type_defs = array("MYSQL_ASSOC","MYSQL_NUM"); // declare default return types do not allow mixed
    
    
if ($return_type !== NULL && in_array($return_type,$type_defs)) // check if the value is not null and is in the array
    
{
        return @
mysql_fetch_array($mysql_query,$return_type); // since it returns a value no need to switch code statements based on value just input the value of the return type
    
}
    else 
// value is either null or is not a supported value force return regular array
    
{
        return  @
mysql_fetch_array($mysql_query);
    }
    
}

static public function 
get_assoc($query)// expects return result i.e a mysql_query use $dbConn->db->sql_query() here
{

    
db_connecter();    
    
    return @
mysql_fetch_assoc($query);
    
}

static public function 
total_rows($query)
{

        
db_connecter();
    
    return @
mysql_num_rows($query);
    
}

static public function 
get_row($query)
{

        
db_connecter();
        return @
mysql_fetch_row($query);

}
     
}
/* create an instance if the class that can be called from any file that includes this script */
$dbConn = new db;

?>
now for getting a result set as a numbered array use

PHP Code:
$q $dbConn->db->get_array("SELECT * FROM table_name WHERE uid=234","MYSQL_NUM"); // access result values as $q[0] 
for the number of rows use

PHP Code:
$q $dbConn->db->total_rows("SELECT * FROM table_name"); // should return the number of rows 
I suggest using the assoc array as your return so you can do a while loop to display the info repeatedly for every returned set or make it easier to process each set of rows. Dont forget that the config has all you fb api info in an associative array when you needed it. Also include the api script from facebook so you can use it and all defines go at the top of the file above the includes.
shabbir like this
bikerboy's Avatar
Go4Expert Member
Thanks for this very much but were do i add this stuff

PHP Code:
 $q $dbConn->db->get_array("SELECT * FROM table_name WHERE uid=234","MYSQL_NUM"); // access result values as $q[0] 
PHP Code:
  $q $dbConn->db->total_rows("SELECT * FROM table_name"); // should return the number of rows 
pein87's Avatar
Ambitious contributor
These are how you access database info, instead of using the whole function process you can simple use the methods I made. Ok lets say you want to get an associative array, generally you'd have to specify the connection stuff , a seperate query call and then the fetch assoc call now you can simple use.

$hiddenMsgs = $dbConn->db->get_assoc("SELECT * FROM table_name WHERE approvedMsg=1");

that would return every message that was approved and they you could use a while loop on it. You will need to know the column names because those are the names that are used for the array keys.

Lets say you have a table with 3 columns id,msg,approvedMsg for the above example you would use

$hiddenMsgs[id];
$hiddenMsgs[msg];

.

Lets do an example

if your using phpmyadmin enter this in the query box or from the command console

Code:
CREATE DATABASE FB_APP;
use FB_APP;
CREATE TABLE hiddenMsgs(id INT NOT NULL AUTO_INCREMENT, msg MEDIUMTEXT NOT NULL, approvedMsg INT NOT NULL DEFAULT 0,PRIMARY KEY(id));
add one row

Code:
INSERT INTO hiddenMsgs (msg) VALUE("It's a meeee Maaarriiooooo");
get row

Code:
SELECT * FROM hiddenMsgs;
this is a sample table it lets you configure if its been approved or not and by default the value is 0.

Now using my class you can do this(make sure config file is set up correctly first)

PHP Code:
//show all rows
while($allMsg $dbConn->db->get_assoc("SELECT * FORM hiddenMsgs"))
{
echo 
"<p>" $allMsg[msg] . "</p>";

I simply made it easier to access the database using a class with methods to certain mysql function.
Set up the config first then include the facebook api file in the class_fb-con.php file then include the class_fb-con.php file in your script were you'll perform your functions to connect to facebook.
shabbir like this
bikerboy's Avatar
Go4Expert Member
now will this add the peps that go to the site to the database
bikerboy's Avatar
Go4Expert Member
that is what i needed done was to add peps to the database
bikerboy's Avatar
Go4Expert Member
Help please
pein87's Avatar
Ambitious contributor
Ok you just want to add people who visit the site to the database? Is there a login system or is it that you want them to be logged in from facebook? You can simple run a query to check if someones IP has visited your site if its not stored in the database add it, or create a user system. My code only makes connecting to the database easier. If you could give me some more in depth details I could better help you and change the code to work better.
bikerboy's Avatar
Go4Expert Member
yes i have a database setup witch you can get here http://immortalbattle.com/eminem/test.zip this would be great to get done right away and i just want then to be logged in from facebook

Thanks for all your help