Get Photoshop help and share your work at PhotoshopForums.com

Bookmark and Share

Common SQL Errors

Common SQL Errors

Postby Thoul » June 2nd 2004, 9:02 am

When installing hacks or running a phpBB forum, many people will encounter an error message on their forum that results from a SQL problem. In this tutorial, we'll look at some of the more common of these error messages, what actually causes the errors, and what you can do to fix them.

Since these error messages are different on a case-by-case basis, we'll be looking at some generic forms of them here. The following placeholders will be used to represent real names in the error messages.
  • Database - The name of your SQL database.
  • Table - The name of a table in your SQL database
  • Table_name - Something representing the name of a table in your SQL database
  • Column - The name of a column in a table.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Postby Thoul » June 2nd 2004, 9:04 am

phpBB Error wrote:SQL Error : 1146 Table 'database.table' doesn't exist

phpBB Error wrote:SQL Error : 1054 Unknown column 'column' in 'field list'


These error messages usually appear when a hack has not been fully installed. Many hacks require changes to your forum's database in order to function correctly. A lot of people don't complete the SQL portions of the installation and then come across an error such as one of these. Fixing these errors is usually simply a matter of completing the SQL portion of the installation. See the Installing phpBB Hacks and Running SQL Queries with db_update.php tutorials for more details on installing SQL changes.

It is also possible that these error messages can appear when a hack is installed or coded incorrectly. While the latter is very rare, the former is an easy situation in which to find yourself. When installing SQL changes, you must be certain that the table prefix (the "phpbb_" in a database table name such as "phpbb_config") in the queries matches that being used on your forum. Most automatic installers (including db_update.php files) will do this for you. If you run the queries manually, however, be sure to check the prefix. The prefix being used on your forum can be found in your config.php file, on this line:
Code: Select all
$table_prefix = 'phpbb_';
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Postby Thoul » June 2nd 2004, 9:07 am

phpBB Error wrote:SQL Error : 1146 Table 'database.TABLE_NAME' doesn't exist


While it appears similar to the first error we looked at above, this message represents an entirely different kind of problem. Notice that TABLE_NAME here is written in all capital letters; this is how you know the error message is different. In phpBB coding, it is a convention that constants, which represent unchangeable values, are written completely in uppercase. An example is USERS_TABLE, which is the constant representing the name of your users database table (the name is your table prefix plus the word "users"). This convention is also used in a lot of broader PHP coding.

When PHP encounters something in a script that it believes is a constant, but cannot find a defined value for that constant, the literal meaning becomes the value of the constant. To put it more simply, if the constant TABLE_NAME is not defined, then the value is assumed to be "TABLE_NAME" when used. The error occurs because there is no database table with this name (note that table names are usually case sensitive and constant names are usually different than actual table names).

In order to fix this error, you need to define a constant. When you're installing a hack and you encounter this error, it'll usually be a result of not making an edit to includes/constants.php or accidentally deleting something in that file. Typically, editing constants.php according to the hack's instructions (or restoring what you accidentally deleted) will define the constant.

Sometimes this error message may also appear in another form containing a SQL query like the one below.
phpBB Error wrote:SELECT * FROM TABLE_NAME
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA


Return to phpBB 2: Troubleshooting

Who is online

Users browsing this forum: No registered users and 0 guests