Need help on database access, problem solved.

Events happening in the community are now at Drupal community events on www.drupal.org.
color's picture

Our website need to read one type of nodes body directly for high performance. The code is as following:
include("opendatabase.php");
$result = mysql_query ("SELECT body FROM node_revisions WHERE uid = 1 AND title = 'test1' LIMIT 1 ");
$row = mysql_fetch_assoc ($result);
print_r ($row["body"]);

mysql_close();

It doesn't run drupal_bootstrap. It has no relation with the drupal except read its database table.
The results is very strange. It can only get a small part of node.body's contents. I have tried different ways to read the data out such as
$obj = mysql_fetch_object($result);
It always show a part of node.body's contents.
We do not load Drupal (version is 6.19) because the potential millions of visits from mobile devices may be a bottleneck.
We need the drupal since the users can edit, revise their nodes.
Is there any trick to read the database tables for Drupal?
Any suggestions are welcome.

Comments

Could you be bit more

exlin's picture

Could you be bit more specific please?
What parts of content you are getting as result. only part of body and is it concurrent. Meaning always showing ex. only first 100 chars from body.

Do you have cck fields?

I would suggest that you

Garrett Albright's picture

I would suggest that you query by vid, not title; it will be faster, since that column is indexed, and you won't run the risk of collisions if there's two node revisions that have the same title, which is almost certain to happen. In fact, perhaps what's happening now is that your query is returning an earlier revision of a node where the body was shorter than it is in later revisions.

Also note that you're not joining any of the tables which store CCK data, so that might also be what's wrong here - you're expecting to see CCK data which is simply not stored in node_revisions.

All said, I highly recommend you reconsider your approach of querying the database this way, and instead do it properly through Drupal. Yes, doing a full bootstrap of Drupal saps performance potential, but there are ways to fix that through caching (I'm guessing very few of those mobile users are going to be logging in, so Boost would work well there), and the behavior will be a lot less unpredictable.

Thank you very much for your

color's picture

Thank you very much for your replies.
What parts of content you are getting as result:
If the body has only a dozen chars, all are showed. If there are a few thousands, only a few hundreds showed. The first part was not showed, the end or the middle part may be showed. Every time, it shows the same part.
Even if the body's contents are new, not revised, can only showed partly.
I put the drupal on maintenance mode, it gets the same result.
There is no CKK data in the nodes we accessed.
Of course, if run drupal_bootstrap, and call load_node, the whole contents can be showed.
We needn't mobile user logged in, but they need read their own nodes. The cache won't work in this case. The drupal really eats too much resource for this tremendous current light visits.

Try to open mysql command

exlin's picture

Try to open mysql command line tool (or mysql workbench) and run query directly against mysql.
See what it returns. If it returns correct, is it possible that way you print result is causing issue, example it filters html out etc...

Thank you very much,

color's picture

Thank you very much, exlin.
It works without code changing this morning.
I think probably the web server's caching mechanism brought this problem.