Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Almost there... using "describe" to check whether a table exists.
Okay, tcm_rating v.2000 is almost ready (and is very, very cool) but I have a problem. I need to check whether a table exists so that I can present an installation screen, and so I looked at the txp source for an example, and I get the line
@if ($connected && safe_query(“describe `”.PFX.“textpattern`”)) {
from index.php. So describe can be used to check whether a table exists. Maybe.
But when I usesafe_query("describe ".PFX."txp_tcm_rqueue");
in my plugin, I get the nasty fatal error
Fatal error: Table 'w_lab.txp_tcm_rqueue' doesn't exist describe txp_tcm_rqueue in /home/.naxos/workingidea/lab.workingidea.com/txp/textpattern/lib/txplib_db.php on line 61
and the whole think nosedives. It’s strange that it would work in one place but not in another. Also I can’t find an alternate way to check table existence (for instance, show tables like… or the like)
Any ideas, wise fellows?
Last edited by tmacwrig (2006-01-19 00:45:15)
Offline
Re: Almost there... using "describe" to check whether a table exists.
“Describe” is actually used to grab the column names from a table. Since the table doesn’t exist it’s spitting out that error. There are a couple ways to get around this.
You can actually have a “create” command that checks to see if the table already exists, and creates the table if it doesn’t. Check out the MySql Doc.
Offline
Re: Almost there... using "describe" to check whether a table exists.
Well, describe is also used by txp itself to check whether the table exists. Having a create query that runs every time will work, and I guess I’ll do it that way.
Offline
Re: Almost there... using "describe" to check whether a table exists.
The problem should go away when you switch production status to live.
The error is triggered by the db-layer. It was introduced because wrong queries were sometimes not generating any feedback to users. Now, making that a fatal error in debug may have been a bit too enthusiastic, I think in the current dev branch it is only a warning that is triggered.
Offline