Jump to content

mysql error code


MarioApprentice

Recommended Posts

Hy everybody for the second time today.

 

I'd like for my catch clause to redirect to a page regarding the mysql error given by a query. Lets say that i mispell a query and get a 1064 sql error code. how to i get it? I've tried googling but with no results. I've also found the errorCode() method that's going with PDO object and PDOStatement but it doesn't work.

Link to comment
Share on other sites

I did come up on errors. That is why i'm asking but i didnt get that far ahead to now how to keep logs but i can imagine how to do it, but the main thing I want to do is get the sql error number. Let's say i get 1062 which is for duplicate code, or when i put the values in a table that are already there and need to be unique. Then i would like to do something like this:

 

//registration of user with the unique values repetied, exception
//sql error code 1062

if(1062 == true)
{
   //redirect to registration page with a message that the username
  //or password or given e-mail already exists
}

 

That's what i want. I'm learning php for 2 months and I figure there's a better way to do this, but this is the best i can understand with a 2 months knowledge. I've tried with the errorCode() method in with the PDOStatement object but it doesn't work.

Link to comment
Share on other sites

Don't rely on error conditions to tell you there's duplicate data. Actually look to see if there's a duplicate entry before trying to add a new one.

 

[edit] If you're paranoid then there are a lot of different errors you can look for. PDOStatement::errorCode() will return something that is not the MySQL error number.

Edited by requinix
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.