Manual talk:Page table
From MediaWiki.org
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).
I'm trying to access the information but I get an error when I place something in the Page_Title spot
wiki_page_title = 'Mrs._Harford' Cannot execute the query: Unknown column 'Mrs._Harford' in 'where clause'
What could be causing this?
if (! $thiscontent = mysql_query('SELECT old_text from wiki_page, wiki_revision, wiki_text where page_title = "Mrs._Harford" and page_latest = rev_id and rev_text_id = old_id')) { die("Cannot execute the query: ".mysqlerror()); } else {echo $thiscontent;}
I figured that the quotes were causing problems, but now I only get Resource Id #3
[edit] quotes
when you ask for »"Mrs._Harford"«, you're actually asking for a column named literally »Mrs._Harford«. this is the effect of double quoting: protecting the content from further interpretation.
what you want is the value »Mrs._Harford«, a string typed value. the way to tell this to the sql parser is by using single quotes: »'Mrs._Harford'«.
obviously, since you are writing this in a string being delimited by single quotes itself, you must escape them.
an other way (a good practice) would be to use double quotes to delimit sql commands.
your text would then look like this:
if (! $thiscontent = mysql_query("SELECT old_text from wiki_page, wiki_revision, wiki_text where page_title = 'Mrs._Harford' and page_latest = rev_id and rev_text_id = old_id")) { die("Cannot execute the query: ".mysqlerror()); } else {echo $thiscontent;}
Note that the above conversation may have been edited or added to since the transfer. If in doubt, check the edit history.
[edit] Moved from page during rewrite
I moved this from Page table: Titoxd(?!?) 08:47, 5 May 2007 (UTC)
To get e.g. the current wikitext of a given page in the main namespace:
SELECT
LEFT(old_text,1024)
FROM
page
INNER JOIN revision ON page_latest = rev_id
INNER JOIN text ON rev_text_id = old_id
WHERE
page_title = 'Your page title'
AND
page_namespace=0;
Note: The use of LEFT(old_text,1024) allows the first 1024 characters to be printed because, old_text being a blob, your query would probably only display "[BLOB - <n>.<n> KiB]" where <n>.<n> is the size in kilobytes of your page content. If you are using this query in a program and need the entire content in old_text, be sure to only reference old_text and not LEFT(old_text,1024).