Jump to content

Highlander

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Everything posted by Highlander

  1. I don't see any problem with just having one database and multiple tables, and then give different applications different type of access to the data (using views or stored procedures). There is no need for using multiple databases when you have connections to different tables.
  2. It's becuase the variabels used in the form are not set yet. How do i work around this? <?php $first = isset($_POST['first']) ? $_POST['first'] : ""; ... First: <input name="first" type="text" value="{$first}" /> {$errors['first']} <br /> ?>
  3. I always use setName() and getName() since I believe that the __get and __set methods removes the clarity of what types of properties an object have. I know that __get and __set can create a more dynamic structure, but that is the price I pay for a clearer code.
  4. I would recommend the second one in your example since the first one adds a dependency that the Util class needs to know about the database when you write test-cases
  5. One site that I find minimalistic but with much information, is http://zenhabits.net. Maybe get some ideas from there
  6. class b extends a{ function show_name($name = null){ if ($name != null) echo $name; } else { echo $this->name; } } } That should work
  7. You would never update a primary key. It is used in the WHERE claus of the update query to define what record to update UPDATE users SET name='joe', email='joe@123.com' WHERE userId='123' I suggest you spend some time on database normalisation Yea, this is the case for normal database with no temporal support. In temporal database you need an ID for each update to the object in a unique row. After some thinking and help from a friend, here is the solution for the database schema: -- Author: Johan Grahn -- Database schema for my blog DROP DATABASE IF EXISTs high_blog; CREATE DATABASE high_blog CHARACTER SET = utf8; USE high_blog; CREATE TABLE user ( username varchar(40) NOT NULL, password varchar(40) NOT NULL, first_name varchar(40) NOT NULL, last_name varchar(50) NOT NULL, id int NOT NULL, revision int NOT NULL DEFAULT 1, st timestamp NOT NULL DEFAULT now(), et timestamp NULL DEFAULT NULL, PRIMARY KEY(id, revision) ) ENGINE=innodb CHARSET=utf8; CREATE TABLE blog_entry ( id int NOT NULL, revision int NOT NULL DEFAULT 1, title varchar(100) NOT NULL, content text NOT NULL, st timestamp NOT NULL DEFAULT now(), et timestamp NULL, author int NOT NULL, author_revision int NOT NULL, PRIMARY KEY (id, revision), FOREIGN KEY (author, author_revision) REFERENCES user(id, revision) ) ENGINE=innodb CHARSET=utf8; In this schema, I store each update to the id in a unique revision so that each user with a given ID can have multiple revisions (each revision contains the updated data for the user).
  8. But this will not work, since the ID will change every time a change is made to the user row (id column has auto_increment), since a new row is inserted for every change so that you can track each change. Hm, I think I need to read more about this.
  9. Hello! I'm trying to build a blog and use a database design that can record history using temporal data. I have a user table that looks like this: CREATE TABLE user ( id int NOT NULL AUTO_INCREMENT, username varchar(40) NOT NULL, password varchar(32) NOT NULL, first_name varchar(40) NOT NULL, last_name varchar(50) NOT NULL, -- Temporal columns st timestamp NOT NULL DEFAULT now(), et timestamp NULL DEFAULT NULL, PRIMARY KEY(id) ) ENGINE=innodb CHARSET=utf8; Now I want to have a blog_post table with a author id connected to the user table, but how do I uniquely store a identifier to the user? My first though was to store ID + st in blog_post table, but it doesn't seem right. Any hints on this?
  10. I would recommend writing a shell-script that polls your directory (or even use inotify) and runs mysql queries if any new files are added. God luck!
  11. And replace #include <iostream.h> with #include <iostream> The first one is meant for C-compiler, not C++
  12. Yea, you need one connection to each database. No, MySQL will not know in which database the given table is, you will have to tell him, by using the appropriate connection.
  13. I think that with todays hardware, you will run out of bandwidth (e.g. many users) before running out of disk space, unless you do a TERRIBLE database design.
  14. Sounds like a very strange article, can you post a link to it ? A class should have ONE purpose, and ONE purpose only. Better to have 10 small classes than 1 big. Better maintainability and structure.
  15. You need to a hidden field in the form that stores the ID of the row that you want to update, like this: <input type="hidden" name="id" value="<?php echo $id?>" /> And then, on the process.php page, get the ID and then perform the query: <?php $estDev = $_POST['estimatedDelivery']; $id = $_POST['id']; mysql_query("UPDATE 'deliveries' SET 'estimatedDelivery' = '$estDev' WHERE row_id = '$id"); ?> This is just an example, and you need to modify it to fit your need, but it is a start
  16. No, it's procedural. Functional programming is a much different paradigm. Yea, my bad. Wrong word
  17. What is stored in $_POST['estimatedDelivery'] ?
  18. I whould say that the first thing to check is to see how much time the database query takes, and if the query uses correct indexes. Look up EXPLAIN SELECT with your MySQL manual
  19. Yea, silly me, haven't had my coffee yet Of course it will take some computing time for each error
  20. Are you trying to use OO design? Because that piece of code is just like regular functional coding. But you are thinking correct when you separate form code from view code.
  21. No, there will not be any performance losses, but why do you run a script with a lot of errors? Why not fix the errors?
  22. I whould agree that data never gets removed since the old data is used for history queries. Data can be moved to other tables but not completely removed. Storage space is not expensive
  23. This is just a quick question: To add copyright to my code, I have added this to each PHP file and HTML file. Is this enough? /* * $Id$ * * Copyright (c) 2008 Johan Grahn * Released under the BSD license * */
  24. Are you using transactions? I mean do you send all INSERT's into one transaction?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.