Storing (html and php) Content in MySQL - help

Storing (html and php) Content in MySQL - help

am 01.12.2009 01:52:39 von Allen McCabe

--001636e0b891c81ddc0479a02ca3
Content-Type: text/plain; charset=ISO-8859-1

I have been trying to wrap my mind around how to accomplish this for a few
days, and done estensive searching on Google.

I know there are free CMS systems available for download, but I want to
write my own code so I can maintain it and extend it, I need it to be
customizable.

So far what I have worked up is this:

The mysql row contains a page_id field, title field, content field, and
sidebar content field.

in index.php:
include("module.php")
$username = findLoggedinUsername()

eval ($content)


in module.php:
$result = mysqlquery("select * from content where page_id = get['id']")
$row = fetcharray9$result)
$content = $row['content']
$title = $row['title']

etc.

The content mysql field contains:

$ct = <<

Welcome $username, to the interweb


END;

echo $ct


In the heredoc, I can use variables like $username, but not like
$row['username'].

So far this method works just fine, however I want to be able to edit the
content through the website itself. Am I on the right track or is this
awkward? I am implementing a new, login system (mine isn't secure enough)
and I want to implement it correctly.

How should I go about storing content (which may or may not include php)
into a page content field?

--001636e0b891c81ddc0479a02ca3--

Re: Storing (html and php) Content in MySQL - help

am 01.12.2009 03:01:16 von John Hicks

Allen McCabe wrote:
> I have been trying to wrap my mind around how to accomplish this for a few
> days, and done estensive searching on Google.
>
> I know there are free CMS systems available for download, but I want to
> write my own code so I can maintain it and extend it, I need it to be
> customizable.
>
> So far what I have worked up is this:
>
> The mysql row contains a page_id field, title field, content field, and
> sidebar content field.
>
> in index.php:
> include("module.php")
> $username = findLoggedinUsername()
>
> eval ($content)
>
>
> in module.php:
> $result = mysqlquery("select * from content where page_id = get['id']")
> $row = fetcharray9$result)
> $content = $row['content']
> $title = $row['title']
>
> etc.
>
> The content mysql field contains:
>
> $ct = << >

Welcome $username, to the interweb


> END;
>
> echo $ct
>
>
> In the heredoc, I can use variables like $username, but not like
> $row['username'].
>
> So far this method works just fine, however I want to be able to edit the
> content through the website itself. Am I on the right track or is this
> awkward? I am implementing a new, login system (mine isn't secure enough)
> and I want to implement it correctly.
>
> How should I go about storing content (which may or may not include php)
> into a page content field?
>

You are definitely trying to reinvent the wheel.

But, having done that myself, I can tell you very generally how I did it.

My content table allowed for multiple rows for each page. Each row had a
label and value (e.g. body:Hello World, sidebar:Goodbye World). To allow
for php code, I added a "type" to each row. (e.g. body:text:Hello World,
sidebar:eval:echo 'Goodbye World';). A template then would have a
function call at the appropriate places to parse the expected content
elements.

As things go, it got a little more complex than that, and then a little
more complex than that, etc.

It's been working fine for me for five or six years and is still
reasonably elegant. I've thought of open sourcing it, but I have a hunch
there are several hundred systems like that already.

Good luck and have fun.

John



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Storing (html and php) Content in MySQL - help

am 01.12.2009 03:08:57 von LinuxManMikeC

On Mon, Nov 30, 2009 at 5:52 PM, Allen McCabe wrote:
> I have been trying to wrap my mind around how to accomplish this for a few
> days, and done estensive searching on Google.
>
> I know there are free CMS systems available for download, but I want to
> write my own code so I can maintain it and extend it, I need it to be
> customizable.
>
> So far what I have worked up is this:
>
> The mysql row contains a page_id field, title field, content field, and
> sidebar content field.
>
> in index.php:
> include("module.php")
> $username = findLoggedinUsername()
>
> eval ($content)
>
>
> in module.php:
> $result = mysqlquery("select * from content where page_id = get['id']")
> $row = fetcharray9$result)
> $content = $row['content']
> $title = $row['title']
>
> etc.
>
> The content mysql field contains:
>
> $ct = << >

Welcome $username, to the interweb


> END;
>
> echo $ct
>
>
> In the heredoc, I can use variables like $username, but not like
> $row['username'].
>
> So far this method works just fine, however I want to be able to edit the
> content through the website itself. Am I on the right track or is this
> awkward? I am implementing a new, login system (mine isn't secure enough)
> and I want to implement it correctly.
>
> How should I go about storing content (which may or may not include php)
> into a page content field?
>

Use curly braces around the variable within the string when using arrays.
http://www.php.net/manual/en/language.types.string.php#langu age.types.string.parsing.complex

echo "Hello {$row['username']}";

However, know that string variable parsing can be very inefficient and
consider this analysis of PHP internals in your design.

http://blog.libssh2.org/index.php?/archives/28-How-long-is-a -piece-of-string.html

On small sites with low traffic it doesn't matter much, but as
complexity and usage grows so does the overhead of writing your code
the "easy" way.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php