Jump to content

Highlander

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Posts posted by Highlander

  1. I'm not a backend developer, just a good developer. I can't tell you the internals of the JDBC but the idea still remains that it's polymorphic and independent of the database and database specific syntax. Sorry I can't elaborate any further how

    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
    Connection conn = DriverManager.getConnection("jdbc:derby:COFFEES");
    PreparedStatement updateSales = con.prepareStatement(
            "UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ? ");
    updateSales.setInt(1, 75); 
    updateSales.setString(2, "Colombian"); 
    updateSales.executeUpdate():
    

    runs. Perhaps it deals with the database drivers that JDBC uses as a proxy, but I have no clue about the java internals, jut the theory.

     

    To me, that looks a lot like PDO.

    http://www.php.net/pdo

  2.  

    I get the following Notice error:

    Notice: Undefined index: first in C:\xampp\htdocs\web\HTML_User.php on line 17

     

    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. 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)

    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).

     

  5. blog_posts

    ========

    blog_id

    user_id

    blog_content

     

    blog_posts.user_id = user.id

     

    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.

     

     

     

  6. 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?

     

  7. what do you mean MySQL doesn't load all content into memory? and what is Sphinx? i developed a simple forum with two tables, Topics and Responses. For the sake of discussion, if my forum EVER got to be as used as phpfreaks would i have to worry about having TOO much in my database?

     

    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.

  8. yah, but i was reading one article and it said something about big classes or using classes for things they are not meant for

    which is what i am doing here

    and i'm just wondering if there's something wrong about it.

     

    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.

  9. 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

     

  10. 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
    *
    */

     

     

×
×
  • 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.