Using mySQL error information

by 4 replies
5
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
#programming #error #information #mysql
  • 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.
  • 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.
    • [1] reply
    • Good suggestion. I'm now 'cleaning' before using.
  • 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.

Next Topics on Trending Feed

  • 5

    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,