Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Hi,

I have a pre-existing site and have been looking for a bolt-in CMS which would allow non techies to update simple content such as page text. CouchCMS seems ideal but there is a catch: The existing site already utilises PHP and MySql to load some of its content. I'm not sure if this is an important detail but this is achieved with custom code, not another CMS.

The content which is already being loaded does not need to be editable by the users who will be making page edits (I hope that makes sense?), so I would like to leave the existing functionality of the site alone if possible.

I've installed CouchCMS (V1.4.7) on the site and merged it into the existing database. The pages load as they should until I add the require couch/cms.php line into the opening php. At this point CouchCMS starts working but my existing SQL connection fails. I get lots of errors along the lines of:

Access denied for user 'root'@'localhost' (using password: NO).

Is there some way I can use my existing SQL queries etc. alongside CouchCMS or is this simply not possible?

I'm open to any ideas. The CouchCMS integration is only taking place inside of a test environment at this stage so I've got nothing to lose trying things out. I'm reasonably proficient with PHP and MySQL but have no idea where to start with this.

Thanks in advance!
Hi,

To begin with, I'd like to unequivocally clarify that Couch has been designed to retrofit into *static* web pages (i.e. plain HTML/CSS/JS).
Pages that already use PHP or MySQL fall outside the purview of 'static' so if you try add Couch on to such pages, all bets are off - the results can be indefinite.

Having said that, if you are willing to put in a little effort we can try to make the existing PHP/MySQL code compatible with Couch.

The trick here is to make Couch invoke PHP. Allow me to explain -
Usually you'll come across existing PHP code enclosed within <?php and ?> e.g. as follows -
Code: Select all
<?php
    echo 'Hello world';
?>

The code above would be executed directly by the PHP interpreter.
What we want to do is to make Couch step in first and then let it invoke the PHP interpreter.
The process is quite easy - we simply replace the <?php and ?> tags with the equivalent <cms:php> and </cms:php> tags e.g. as follows -
Code: Select all
<cms:php>
    echo 'Hello world';
</cms:php>

Mostly no other change is required except one very important one that you need to know.
Please see the following raw PHP code
Code: Select all
<?php
    echo $my_message;
?>

In the code above, the $my_message variable is likely a global variable defined elsewhere in the code and the statement above will print the value contained within it.

To port the code above to Couch, if we simply replace the <?php and ?> as follows the echo statement will not print anything -
Code: Select all
<cms:php>
   echo $my_message;
</cms:php>

To make it work, we'd also need to define the $my_message variable as 'global' as follows -
Code: Select all
<cms:php>
   global $my_message;

   echo $my_message;
</cms:php>

That is because you may regard the <cms:php> </cms:php> block to have a scope of it own (pretty much like a PHP function).

If you got the point being made above, you can see that we can make discrete <cms:php> blocks share data and work by judiciously using the 'global' statement, for example as follows where one block defines a variable and the other uses it -
Code: Select all
<cms:php>
   global $my_message;
   $my_message = 'Hello World';
</cms:php>
..
..
..
<cms:php>
   global $my_message;
   echo $my_message;
</cms:php>

I stressed the 'global' point above, because in your existing code you'll likely have variables (e.g. the database connection etc.) defined somewhere in the header and then being used elsewhere - you'll have to use the 'global' declaration to make available those variables once you try to execute PHP through Couch.

Please try using this technique and let us know if it helps.
Hi KK,

Thanks for such a thorough and clear response.

I appreciate that Couch was developed for static sites and my situation is somewhat fringe. Unfortunately (for me), there are quite a few sections of the site which wouldn't need editing functionality and updating everything to be Couch compatible would be quite a big job. I suspect it may be simpler for me to just build a custom solution.

Thanks again.
@SG, sent a PM a while ago, please check you PM inbox :)
I ran into a similar issue, I am developing a school website to replace a rather inferior looking one, but the existing site (the inferior one) has a student's section which has quite a number of entries.

Could Couch manage future entries but also display the previous ones? I have no idea yet which CMS was used..
---
You live many times, but only ever remember your lives.length - 1
---
Image
cholasimmons wrote: I ran into a similar issue, I am developing a school website to replace a rather inferior looking one, but the existing site (the inferior one) has a student's section which has quite a number of entries.

Could Couch manage future entries but also display the previous ones? I have no idea yet which CMS was used..


Any data CouchCMS operates with must be stored in its database.. Filters, Search, Publsh, Archives - these are sample features that will work as expected only on new (couch-managed) data. I'd say you should seriously consider moving old entries to the new backend. A script that reads old data and creates entries in Couch can be done fairly quickly to avoid manual transfer.
6 posts Page 1 of 1