Using mySQL error information

4 replies
I'm getting an error with a CREATE table query. I know what the problem is (I'm creating tables dynamically and now and then a name slips through with a space or other illegal character.)
The error occurs in a function and what I want to know is, is there a system field/flag which I can use after the return in an if statement to detect whether an error has taken place or not.
Thanks,
Mike
#error #information #mysql
  • Profile picture of the author pdjsolutions
    Hi there Mike,

    PHP mysql_error() Function

    I think that should help you out.

    Its basically a function where you can check whether a statment has been executed properly or not.

    I think that should help.

    Prateek.
    PDJSolutions.
    {{ DiscussionBoard.errors[2224916].message }}
  • Profile picture of the author SteveJohnson
    Originally Posted by MikeHayes View Post

    I'm getting an error with a CREATE table query. I know what the problem is (I'm creating tables dynamically and now and then a name slips through with a space or other illegal character.)
    The error occurs in a function and what I want to know is, is there a system field/flag which I can use after the return in an if statement to detect whether an error has taken place or not.
    Thanks,
    Mike
    While it is definitely useful to know where the error is coming from, stepping back and looking at the bigger picture will show you that you can eliminate the CREATE error completely by filtering the name before you run the query.

    You can either check the name and kick it back with an error if it is illegal, or you can 'legalize' the name that exists by removing illegal characters.

    You should also check to see if the table name exists before you try and create it.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[2226364].message }}
    • Profile picture of the author MikeHayes
      Good suggestion. I'm now 'cleaning' before using.
      Signature

      * * * * My site * * * *
      * * * * My paintings * * * *

      {{ DiscussionBoard.errors[2230341].message }}
  • Profile picture of the author stma
    You can still create table with spaces but you might find wrapping with a ` (not a single quote but the key next to the number 1) helps. With out seeing what you are a doing it's hard to help.
    {{ DiscussionBoard.errors[2226927].message }}

Trending Topics