Is it dangerous to access wordpress tables directly? - php

I'm coding an iOS app that will share information with a wordpress site.
I had originally created a separate database with a custom data entry page in php but the client would like data entry to be done via wordpress forms for both user and admin.
So the easiest way to modify my code is just to look at the table wordpress creates and read from it directly. Is this common practice or considered a no-no?

If you're hosted on Wordpress.com, you can use the REST API documented here:
http://developer.wordpress.com/docs/api/
Otherwise, your main alternative is a third-party REST API plugin, which you could use to give your iOS app access via HTTP to whatever data and CRUD operations you choose. Here are links to a few of those:
http://wordpress.org/plugins/json-api/
http://thermal-api.com/
http://jetpack.me/support/json-api/
What you're describing is both a common practice and considered a no-no.

Just install a JSON/XML plugin in your Wordpress system and get the data from there. Best option you got in my opinion.. A separate database needs to be synchronized with the wordpress database, which is a pain in the ass..

Related

How remove main table in database in wordpress without losing wordpress site?

How can I remove one table from wordpress tables without losing wordpress site?
I mean the main tables, not the plugin tables.
For example, the comment table or post table - if I remove it from phpmyadmin and then go back to the wordpress site it shows me an error and starts repairing the database. I want to be able to delete for example the comment table or option table or the main table without losing the wordpress site. I want just the user table in the wordpress site, and want to remove the other tables.
How I can edit wordpress core files that don't check the database table or just check if the user table exists?
Thanks.
Best regards
As noted in the comments, WordPress requires all the tables that it creates, even if it doesn't seem like it is using them. You can absolutely build a system that only uses WordPress for authentication and/or authorization (I've built several), but you must accept that the other tables and all of the core code exists.
If instead you just want a secure login and session, I would encourage you to look at a library such as PHP-Auth or even better, Symfony. With the latter you can very easy get an authentication and authorization in place and then move on to your code.
However, if you are dead-set on using WordPress, and you are willing to accept that the other tables must exist even if you aren't using them, here's some code that we've used successfully on many sites. The documentation is pretty good but generally it relies on overriding WordPress's action for template_include which allows you to run whatever file/code you want. We almost always pair that code with this theme whose sole purpose is to force users to login before doing anything.
Explaining everything in there is out of scope for this site, and I would very much encourage you to not use it unless you have a very specific need that cannot be satisfied by using a third-party library.

Persistent header and side-bars across multiple web-pages

I'm working on a website I eventually plan on purchasing a domain for and having, hopefully, many users. Of course, a lot of people plan on that and it never comes true! Regardless, I'm progressing forward with the intent of having a good looking interface that's efficient in it's data usage.
One thing I would very much like to do is to have my banner / header and side-bars persist when they navigate to separate pages inside my site. My header contains the site-wide context menu as well as login and profile information, and the side-bars are currently undecided, but potentially just static images.
I don't know exactly how I would do it well. I could just use my PHP session object, but I'd like to be as efficient as possible.
I'm using a traditional LAMP stack, HTML, JS and CSS (using the Bootstrap library) on Ubuntu on an Amazon's EC2 service.
You could create a file with header and sidebar and then use this php code:
include("nameofthefile.php");
on every file of your site

How do I create a web service that will display in a browser and on an android?

My web development experience has mostly been setting up a CMS like Wordpress or Drupal and creating custom themes. Actually work in server-size coding has been very minimal. I've played around with php a little, trying to mod off of phpBB and beginning to learn some MVC work with CodeIgniter. Overall, this seems like a pretty big step forward, but it's something I need (I think) to do for a project I am working on.
Essentially what I want to do is have a service like Twitter of Facebook (not in the social networking sense); a user is able to log into the site and perform various operations, while also being able to use an android application that supports limited operations.
After some Googling and reading articles on the internet, it appears REST is the way to go. But I can't quite seem to grasp some of the technical details. I understand how the HTTP Request/Response works, but I don't know how I can code everything server side so that visiting example.com/item/1 will bring up the details of item 1 in the browser and can also perform a GET Request in my Android app so it can grab the details from the database and display in on the site.
Any suggested readings or some tips on how to execute this?
You can implement this using MVC. By default, have the controller ask the model for the details of the item, then pass the info to the view. Repeat this process for each type of request you want to accept such as POST, PUT etc., where you define a new function in the controller, ask the model to perform the corresponding database action, and return the response to the view.
There is helpful tutorial for getting a REST server up and running using CodeIgniter here

Lightweight codeigniter/php cms that easily plugs into site code

I have another codeigniter CMS suggestion question. Pretty much I am just looking for a CMS that allows my client to easily add in content that doesn't necessarily need to be tied into a page. I pretty much want a MYSQL database with a gui that allows the client to upload content to certain tables in the db. I don't want any themes attached to the cms as the site code will all be custom built and I would prefer to write all the db calls to pull data for specific pages. I just need a way for the client to easily upload data to a table where I can create a model to pull the data.
I have heard of FuelCMS, Ionize, and PyroCMS but all these seem like they have too much. I am looking for a pretty barebones db that has a gui and good documentation for the api's. That's all.
Thanks!
I know you wouldn't think of ExpressionEngine as "lightweight" but from the perspective that you are speaking, it is...
It allows complete control of content separate from any design's or concepts of "pages". It's power is that you define "objects" or channels that contain specific information that you then take and construct the pages around. Channels are a more user friendly concept of the MYSQL tables you're talking about.
DownsideYou get good support because it's not free, but and worth the money.
It's module development pattern is familiar if you are a codeigniter developer also.

Are there any PHP Frameworks (e.g. CodeIgniter) that support database connections on a per user account basis for use in a Multi-tenant database?

I'm looking into developing a multi-tenant SaaS application, and I found several sites that describe a solid way to separate the data using tenantIDs and updateable views. e.g. This blog post
It all hinges on the ability to have your user accounts authenticated from a master users table and then having their respective database connections use those user-specific credentials. This way, the views can pull the userid and map it to the tenantID to display that user's view. However, most PHP frameworks tend to be very static when it comes to database connections (stored in text config files). They appear to be at odds.
Does anyone know:
a) how to make CodeIgniter handle this gracefully?
b) a different PHP framework that might?
At a horrendously basic level you can do this:
http://philsturgeon.co.uk/blog/2009/06/How-to-Multi-site-CodeIgniter-Set-up
Expand it as required, or move the logic into MY_Controller for more flexibility.
There is a topic talking about this on the Code Igniter forums.
http://codeigniter.com/forums/viewthread/165227/#846845
It looks like you set up your users DB as your main database in the config file, then you generate a config array for a new connection for a user based upon information in that users DB. So, I guess you'd need to at least store the DB name in the users database.
Not sure how well this works though, as I haven't had an occasion to try it out yet.
Sorry if that's not quite what you were looking for, but it should give you an idea of a Code Igniter approach.
Zend Framework.
http://framework.zend.com/manual/en/learning.multiuser.intro.html

Categories