Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-12-02 22:46:39
- evan
- Member
- Registered: 2010-01-31
- Posts: 16
writing directly to TXP database
Hi,
I was wondering if I’d encounter any problems with writing directly to the TXP database.
I tried adding an entry manually via phpMyAdmin and it seemed to work OK.
I’m looking to create a custom PHP script that would update an inventory in TXP, and as far as I can tell this would be the easiest way for me to accomplish this, unless there’s a convenient way to add TXP entries via PHP that I don’t know about.
Thanks!
-evan
Offline
Re: writing directly to TXP database
Try to look at this list of internal php functions
You will be interested in functions with prefix safe_...
, i.e. safe_query
and others.
Wiki has some describtions of them
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: writing directly to TXP database
What table(s) are you updating? With some tables it is definitely safer to use built-in Txp functions to ensure data integrity. (txp_category
for one). At a minimum you should generally use the various safe_
functions as Victor suggests. An easy way to gain access to these functions is to package your custom code as a plugin.
Code is topiary
Offline
Re: writing directly to TXP database
Remember to use mem_form
and mem_simple_form
for easy access (write and edit) to textpattern database tables.
Offline
Re: writing directly to TXP database
… and if you are just talking about getting a lot of infos into txp, maybe this also relevant: jmd_csv
TXP Builders – finely-crafted code, design and txp
Offline
#6 2010-12-03 18:24:33
- evan
- Member
- Registered: 2010-01-31
- Posts: 16
Re: writing directly to TXP database
Thanks for the responses, everyone. I’ll look into the plugin aspect again. A quick question though — is it possible for a plugin to run on a schedule, i.e. run a function daily, without user interaction?
To be more specific about my problem, I’m trying to maintain a web inventory, which will reflect a physical inventory on another system, which I’d like to be updated daily. The other inventory system will provide a CSV, which will automatically uploaded to a specified place on our server. I’m trying to figure out how to create and update articles from this CSV so I can use yab_shop
.
My thinking is that the inventory items will created as articles in a specific category from the CSV. The script will, on a daily basis, delete all articles from that category and create new ones from the CSV.
I suppose the simplest solution would be to modify jmd_csv
for my purposes. I’ll poke around in it and keep reading the documentation on plugins.
Offline
Re: writing directly to TXP database
evan wrote:
My thinking is that the inventory items will created as articles in a specific category from the CSV. The script will, on a daily basis, delete all articles from that category and create new ones from the CSV.
An easy solution is to turn the CSV file into an RSS feed and then read it into your site with the SimplePie plugin.
We Love TXP . TXP Themes . TXP Tags . TXP Planet . TXP Make
Offline
#8 2010-12-03 21:48:35
- evan
- Member
- Registered: 2010-01-31
- Posts: 16
Re: writing directly to TXP database
hcgtv wrote:
An easy solution is to turn the CSV file into an RSS feed and then read it into your site with the SimplePie plugin.
I’d like to have the inventory as articles. Does SimplePie let you do this? As far as I can tell, it just lets you display RSS feeds.
Last edited by evan (2010-12-03 21:50:30)
Offline
Re: writing directly to TXP database
evan wrote:
Thanks for the responses, everyone. I’ll look into the plugin aspect again. A quick question though — is it possible for a plugin to run on a schedule, i.e. run a function daily, without user interaction?
No, not directly. You may indeed do better with an external script as opposed to a plugin, and trigger it with cron.
My thinking is that the inventory items will created as articles in a specific category from the CSV. The script will, on a daily basis, delete all articles from that category and create new ones from the CSV.
Keep in mind that textpattern.ID
is an auto-increment field, so that if you delete an article and then recreate it, it will have a different ID (unless you use import
rather than insert
).
Code is topiary
Offline
Re: writing directly to TXP database
evan wrote:
I’d like to have the inventory as articles. Does SimplePie let you do this? As far as I can tell, it just lets you display RSS feeds.
Just tweak the plugin to your liking, like this news page.
The only reason I mentioned it is because you said it needed to be refreshed everyday, so why add articles and then delete them the next day when you can make a feed look like anything you desire.
I make use of feeds in a lot of places, rather than have a static page, I can make it look like content.
We Love TXP . TXP Themes . TXP Tags . TXP Planet . TXP Make
Offline
#11 2010-12-04 07:30:07
- evan
- Member
- Registered: 2010-01-31
- Posts: 16
Re: writing directly to TXP database
jsoo wrote:
Keep in mind that
textpattern.ID
is an auto-increment field, so that if you delete an article and then recreate it, it will have a different ID (unless you useimport
rather thaninsert
).
Thanks, good point. Did you mean update
, though?
hcgtv wrote:
The only reason I mentioned it is because you said it needed to be refreshed everyday, so why add articles and then delete them the next day when you can make a feed look like anything you desire.
I’d like to use articles because I’d like to use yab_shop
. Articles also allow me to add categories, descriptions, etc. so I can make my inventory sortable and searchable in various ways.
Thanks again to everyone for responding. I’m not exactly a wizard at coding, and this is a relatively ambitious thing for me to pull off by my lonesome, so I’m glad to see I’m not just dreaming up ways to mess up TXP!
Offline
Re: writing directly to TXP database
evan wrote:
Did you mean
update
, though?
update
or import
. You mentioned deleting articles daily so I said import
, but certainly there are advantages to updating rather than deleting and recreating.
Code is topiary
Offline