Search code examples
phpsqldatabaseinsertarticle

Best way to store articles in a database? (php and sql)


I want to store articles in a database, but I cannot seem to find much information on the best way to do this, from what I have read it seems split between most people on how to effectively do this. A lot of people will suggest a way and others will point out sql injection issues, and I cannot seem to find much about this topic that is fairly new.

Here is the html of an article:

    <div id="main">

        <article>

            <header>
                <h3> Title </h3>
                <time pubdate="pubdate"> 2011-07-22 </time>
            </header>

            <p> Article Text </p>

        </article>

    </div>

Ideally I guess it would be best to store the chunk of html making up each article into a database but there seems to be a lot of problems with this, and like I said I can't find many posts over this particular topic, and as someone new to php and databases I want to get some input on the best way to go about this before I proceed.


Solution

  • Store your article as TEXT :) Just pass it through this php function first to prevent injection attacks:

    // Prevent MySQL Injection Attacks
    function cleanQuery($string){
        if(get_magic_quotes_gpc())  // prevents duplicate backslashes
            $string = stripslashes($string);
        return mysql_escape_string($string);
    }