Jump to content

[SOLVED] Checking to see if field name exists within a table?


blackcell

Recommended Posts

Errors? You simply query to see if there is a table with that name... no different than any other "count".

So I am assuming now that there is a command to execute a 'check for existence' query.  That is what I meant in the first place.  I will try to look around but I am so buried in home work that I have a hard time find the time to dig deeper into this issue for work.  I also need to study on the php try.  It sounds like it will do something I want to implement in a few programs but I don't understand it from a quick glance.  At any rate thank you for your input.

Link to comment
Share on other sites

I think this is a case where if you describe what you are trying to accomplish, rather than describing what you are trying to do (sometimes what you are doing doesn't have anything to do with the overall goal), someone can provide the best way of accomplishing it. In this case, why do you need to find if a field exists?

 

A query referencing a column that does not exist will fail and return a FALSE value. As long as your code contains proper logic to test the value returned by the mysql_query() function call and does not blindly reference the nonexistent result set, no php error will be generated, which seems to be what is happening now.

 

Link to comment
Share on other sites

OK, I am building a setup/diagnostic routine that will ensure that the required database is setup correctly, and properly named. I do not want to return mysql errors so that the user sees them.  Therefore that is what I am trying to accomplish and DO. I don't want lame mysql errors to appear, because it doesn't seem like good design.  I just want a field to be highlighted in red saying

"`database` doesn't exist.  Attempt to repair? <---then they click on this to try to correct the problem.  Does that properly define what I am trying to accomplish rather than what I am trying to DO?

Plus, I want the general knowledge and best method of approach to this for future reference.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.