0

I am trying to Merge several psets.

But to do that I think I need to have multiple databases.

My dumbest approach to that problem follows like this

in constants.php

 define("DATABASE", "pset7");
define("DATABASE_One", "pset8");

// your database's password
define("PASSWORD", "123");

// your database's server
define("SERVER", "localhost");

// your database's username
define("USERNAME", "root");
date_default_timezone_set('Asia/Kolkata');

in functions.php function query(/* $sql [, ... ] */) {

            // connect to database
            $handle = new PDO("mysql:dbname=" . DATABASE . ";host=" . SERVER, USERNAME, PASSWORD);

}

 function query1(/* $sql [, ... ] */)
{

            // connect to database
            $handle = new PDO("mysql:dbname=" . DATABASE_One . ";host=" . SERVER, USERNAME, PASSWORD);

}

I created exact copy of query() in that I changed dbname from DATABASE to DATABASE_One

I don't know whether it works or not but If you have correct or better approach please help me.

If possible suggestions on how to merge two psets will be much appreciated. I am thinking about about subfolders or subdomains approach.

1 Answer 1

1

Admittedly I don't fully grasp what you mean "merge several psets". However,in the narrow and specific context of CS50 pset7 & pset8, you do not need two databases. Consider adding the places table to the pset7 database. You wouldn't have to change any config files or functions. (You'd have to modify pset8.sql for database name change).

Adding the "shadow" query is, generally speaking, a bad idea. Kinda defeats the purpose of a "merge" if you have to have separate functions anyway.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .