Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2008-10-27 21:30:29
- charlbury
- New Member
- Registered: 2008-10-04
- Posts: 2
Adding, updating and reading from a database table
Hallo
I’m putting together a site that will show several tables of information. The information will be updated quite regularly.
The info would clearly be best held in a couple of database tables and read from those tables whenever the page is displayed.
Can anyone point me in the direction of information about how to create TextPattern pages that use PHP to read data from MYSQL database tables?
Also, a couple of specific questions.
1. Is it best to create any new tables in the textpattern database alongside the textpattern tables, or, is it best to create the data tables in a new database completely separate from the textpattern database?
2. Would it be best to look for a plugin to help me write to and read from database tables? Does one exist? Or just code the database calls directly into a textpattern page?
Thanks
Last edited by charlbury (2008-10-27 21:31:09)
Offline
Re: Adding, updating and reading from a database table
charlbury wrote:
Can anyone point me in the direction of information about how to create TextPattern pages that use PHP to read data from MYSQL database tables?
I think there are a couple of resources in Textbook that I can’t find right now (typical!) on how to interact with a database but the core functions you need are found in lib/txplib_db.php
. All the safe_* functions are there to help you get stuff in and out of the database. The safe_rows
/ safe_row
and safe_column
functions are best for getting simple stuff in and out, but if you want complete control then safe_query
is your friend:
<txp:php>
global $whatever_globals_you_need;
$rs = safe_query("Select * from my_new_table WHERE blah blah");
foreach ($rs as $row) {
// Do some stuff with $row
}
</txp:php>
Is it best to create any new tables in the textpattern database alongside the textpattern tables
I find so, yes. Simply because you don’t have to worry about CONNECTing to them, as it’s done for you by TXP.
Would it be best to look for a plugin to help me write to and read from database tables?
You could try smd_query written for just such a purpose :-)
Hope that helps.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline