Miyazaki
Aug 15 2006, 02:34 PM
I can't find the thread Nikiwu put up about the database design so I have created this one.
I have come across this tool called
Aqua Data Studio which is supposed to allow a user to design, create and manipulate databases in one Java-based IDE.
I haven't had a chance to use it yet but here it is anyhow for everyone else to try.
I small note when downloading, if you have the Java 1.5 already installed, go for the Java-enabled OS version and save 30+ megabytes of download.
nikiwu
Aug 15 2006, 03:38 PM
I've removed that post as no-one was willing to assist me with my design.
I have since began to muck around with mysql on my webserver, slowly learning how everything works. I've managed to create a database using Navicat MySQL (recommended by a friend who setup my webserver), and have got a few php files working to add and display data. I'm in the process of trying to create an external/header file that connects to an MySQL database, and where I can call an sql query, so I don't have to retype the whole db connect code in each php file I create. I'm currently having trouble getting it to work.
It seems I'm not skilled enough to know how to do stuff like that properly.
I'm trying to create a "dargh admin" website that I can use to display all the data from the new site (news, events, anime list... etc), and where I can add, update and edit data. Once I get it working, I can simply incorporate the data from the db into the new site for display.
But, it's gonna take me a while to complete it, as I'm learning while developing, WITHOUT any assistance.
Miyazaki
Aug 16 2006, 09:52 AM
I've created a few PHP Classes for creating database objects a couple of years ago.
Would you like me to go find them so you have a few examples to work with?
I must tell you in advance, they issues of their own. While the code I wrote took the headache out of always creating database connections, the program had to ensure that the object instance was retained at all times.
Have you tried using Eclipse, Nikiwu? It's like Visual Studio but is for free and doesn't stall as much on startup. While the main drive to Eclipse is Java development, it has plugins for working with Perl, PHP and C/C++.
nikiwu
Aug 16 2006, 03:30 PM
I created a class file, though whenever I try to include it with a php file, it doesn't work..
anyway, this was my attempt at creating a simple mysql db class by looking at other source codes I could find (phpBB and a downloaded blog) while trying not to copy and understand it.
class db
{
var $dbcon;
var $qcount = 0;
ver $qresult;
function db_connect($name, $password, $database) {
$this->dbcon = @mysql_connect(localhost,$name,$password);
if($this->dbcon) {
echo "connecting";
@mysql_select_db($database);
}
}
function db_close() {
@mysql_close($this->dbcon);
}
function s_query($query) {
echo $query;
if($query != "") {
$this->qcount++;
$this->qresult = @mysql_query($query, $this->dbcon);
} else {
echo "No Query<br \>\n";
exit;
}
if($this->qresult) {
return $this->qresult;
}
}
}
I have no idea how classes work with db connections, nor do I know how to set a connection up with an external file. This is how I tried to set it out in my php file:
include "db_class.php";
$username="#######";
$password="#########";
$database="################";
$dDB = new db();
$dDB->db_connect($username, $password, $database);
$result = $dDB->s_query("SELECT t_p, t_m, p_tt, p_tx, u_id FROM d_n where id=".$n_id."");
$dDB->db_close();
Back to the drawing board I guess..
Miyazaki
Aug 16 2006, 04:14 PM
What is the '@' for? Address? Forgive my ignorance but I didn't get to play with PHP for long.
What is the error you are getting anyway?
If it's saying the file has alreay been included then it means multiple scripts are trying to include the file when PHP demands it only be done once.
To stop a file from being include more than once, you have to keep some form of switch in the file so it can be told where the file has been included or not.
For example, say I have a file called 'my_class.php'. The first thing to put in the strip file would be:
if( ! $MY_CLASS_INCLUDED ) $MY_CLASS_INCLUDED = true;
Next, when I go to include the file, I would do so with the line:
if( ! $MY_CLASS_INCLUDED ) include( "my_class.php" );
I'm not sure if this is the correct line for including files, but the idea is still the same.
EDIT --
I think you also need a colon ';' after the outer most bracket of the class definition.
Also, the third variable in you code has $ver instead of $var infront of it.
nikiwu
Aug 16 2006, 04:56 PM
that's one thing I don't like about working with php.. it fails with errors, and you can't find them easily.
The error I was getting was a blank page, the actual class file had an error, and I couldn't figure out where..
After fixing the errors you have stated, as well as adding a colin at the end of the class definition, my class db file is interacting with the external php file.
Thanks.
Not sure what the '@' is for. I just noticed it at the other sql classes and basic mysql tutorial sites I've been looking at..
Miyazaki
Aug 16 2006, 05:01 PM
You're welcome. Feel free to ask for help. But I must warn you, I'm busy now these days with the possible conversion to PhD.
I have to get my current work up and running by the end of the week and there is still much to do.
All the same, best of luck with your coding.
nikiwu
Aug 17 2006, 04:21 PM
I managed to get a login/logout function working. I also got an edit/add function working for the news today.
Slowly getting there.
Lortarg
Aug 17 2006, 04:36 PM
If you want help with PHP ask Zombos.
nikiwu
Aug 18 2006, 11:04 AM
Thanks for the advice. I might ask for help if I'm really stuck on a something. I've managed to find alot of useful stuff online, which have helped me with any small problems I have. php.net is really giving some great info on alot of different commands, especially with the user comments/feedback.
hopefully, today I'll get a "delete" function working, as well as starting to incorporate the "events" db.
nikiwu
Aug 19 2006, 03:43 PM
ok.. i'm confused as to why this is occuring.
I'm using time() to store the current time whenever someone posts a new news item to the database. However, it seems that the time is not accurate.. it's nearly 10 hours behind the actual time.
Not sure why it's doing it. I haven't found anything online in relations to my problem?
*shrugs*
Miyazaki
Aug 19 2006, 05:15 PM
The function must be working to UTC time, whatever that means. It works on what the time is at Greenach and we are 10 hours different.
nikiwu
Aug 19 2006, 11:22 PM
It's actually 15 hours behind.. way off.
could be my server.. will double check once I setup the site on the dargh server. If it's still getting the same problems, I'll just simply add the 15 hours to the value.
TheHeadSage
Sep 1 2006, 04:36 PM
Set the timezone with "setvar" I think. I'll look at my own scripts for the full code snippit.
This server is GMT -3 or GMT -5 I believe.
Also, don't hard code it as localhost. For DB connections, is will most likely be either mysql.dargh.com or mysql.sagestower.com.
nikiwu
Sep 3 2006, 02:01 PM
I simply added the hours to the time variable... I've also changed that code to use a set "host", instead of localhost.
Anyway, I'm new to all this stuff... So I'm bound to not do things properly.. But as long as it's working, I'm happy...
TheHeadSage
Sep 3 2006, 08:46 PM
Well, I'm finishing a huge glut of assignments soon, so if you want me to help you or give the code a quick run through, then just ask.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.