In the following code I'm trying to figure out what InitDB is? I need to reconfigure these files for a particular website and to use SQLite. http://www.html-form-guide.com/php-form/php-registration-form.html

<?PHP
require_once("./include/fg_membersite.php");

$fgmembersite = new FGMembersite();

//Provide your site name here
$fgmembersite->SetWebsiteName('user11.com');

//Provide the email address where you want to get notifications
$fgmembersite->SetAdminEmail('user11@user11.com');

//Provide your database login details here:
//hostname, user name, password, database name and table name
//note that the script will create the table (for example, fgusers in this case)
//by itself on submitting register.php for the first time
$fgmembersite->InitDB(/*hostname*/'localhost',
                      /*username*/'prasanth',
                      /*password*/'p',
                      /*database name*/'testdb',
                      /*table name*/'fgusers3');

//For better security. Get a random string from this link: http://tinyurl.com/randstr
// and put it here
$fgmembersite->SetRandomKey('qSRcVS6DrTzrPvr');

?>

It seems a method of the class FGMembersite() to start a database connection, check in ./include/fg_membersite.php for more details.

How hard would it be to convert the project from the link I gave above to SQLite?

Hi,

To be able to use sqlite, you will have to use PDO wrapper. The most basic PDO approach can be something similar to this..

try {

$conSql= new PDO("sqlite:PathOfYourDatabase");

}
## catch exception right after the try
catch(PDOException $error){
echo $error->getMessage();
}

The linked script above is old, I am pretty sure it will have difficulty thrieving in the latest PHP environment. For example, looking at the class itself it is more of a backward compatible to the older version of PHP. So, the best way to make the script compatible to what you are trying to achieved is to make an upgrade.. In this part of the code,

class FGMembersite
{
var $admin_email;
var $from_address;

var $username;
var $pwd;
var $database;
var $tablename;
var $connection;
var $rand_key;

var $site_name; // this is from the salt.php
var $randK; // this is from the salt.php
var $userType = false;
var $userSess = null;
var $user;


var $error_message;

//-----Initialization -------
function FGMembersite()
{
    $this->sitename = $this->site_name;
    $this->rand_key = $this->randK;
}

function InitDB($host,$uname,$pwd,$database,$tablename)
{
    $this->db_host  = $host;
    $this->username = $uname;
    $this->pwd  = $pwd;
    $this->database  = $database;
    $this->tablename = $tablename;

}

You may want to upgrade it to something like this..

class FGMembersite{

## if you want you can itimize them nicely..

private $admin_email, $from_address, $username, $pwd, $database, $tablename, $connection, $rand_key, $site_name, $randK, var $user;

## like these
private $userType = false;
private $userSess = null;
private $error_message;


public function __construct(){

## we can create an instance of the PDO in this very constructor if we want
try {

$this->connection = new PDO("sqlite:PathOfYourDatabase");

## change the attribute to something beneficial for you during development. I don't have it in my head right now..

$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
    //echo 'connected';
      return true;
}

catch(PDOException $e){
 ## you must select one return false or die
//return false;

die('There is a connection error: ' .$e->getMessage());
}

}

/*
* @method returns the pdo connection
*@least it is private for this class to use
*/

private function isDb(){
    return $this->connection;

}

Now, let us practice on the given script from the link.. let us take a look at the database table creation..

function CreateTable()
{
    $qry = "Create Table $this->tablename (".
            "id_user INT NOT NULL AUTO_INCREMENT ,".
            "name VARCHAR( 128 ) NOT NULL ,".
            "privs int(11) NOT NULL,".
            "email VARCHAR( 64 ) NOT NULL ,".
            "phone_number VARCHAR( 16 ) NOT NULL ,".
            "username VARCHAR( 16 ) NOT NULL ,".
            "password VARCHAR( 32 ) NOT NULL ,".
            "confirmcode VARCHAR(32) ,".
            "PRIMARY KEY ( id_user )".
            ")";

    if(!mysql_query($qry,$this->connection))
    {
        $this->HandleDBError("Error creating the table \nquery was\n $qry");
        return false;
    }
    return true;
}

again the code above is nearly absolete by next week's PHP upgrade or so.. we eliminate some of the junk or fragments from mysql..remember this->tablename is coming from your include file, if not just type in the name of the database as it applies to sqllite.

function CreateTable(){
    if($isDb){
    $this->connection->exec ("CREATE TABLE IF NOT EXISTS $this->tablename (
            id_user INTEGER PRIMARY KEY,
            name TEXT,
            email VARCHAR( 64 ), // not sure, alternatively you can TEXT
            phone_number VARCHAR( 16 ),
            username VARCHAR( 16 ) ,
            password VARCHAR( 32 ) ,
            confirmcode VARCHAR(32))
            ");
  }

  else{

  echo 'Database table creation failed';

 }

 }

Ok, my attention span have already gone away, so just do the same approach to the remaining methods that has mysql in it.

good luck to you... sorry about that, I thought I will be able to do at least 3 methods, but I have the same attention span as gold fish... :) + laziness is hovering on top of my head..

please double check my sqllite syntax to make sure they are properly implemented in the table creation..

VERY IMPORTANT! change the password hashing to something else, but MD5..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.