PDA

View Full Version : mysql_query error number


Fraxter
02-09-2013, 06:18 PM
Hi at all.

I've a small question. How is it possible to not show the db error and another self defined error in vbulletin?

My actual code looks like this, but it shows only the default vbulletin database error if an entry is duplicate:

$query = @$db->query_write ("INSERT INTO files
(info_hash,
name,
filename,
category,
size,
added)
VALUES
('" . $arr[1] . "',
'" . $db->escape_string ($vbulletin->GPC['name']) . "',
'" . $db->escape_string ($file_name) . "',
" . $vbulletin->GPC['category'] . ",
" . intval ($arr[4]) . ",
'".date('Y-m-d H:i:s')."')
");
if (!$query) { //this part doesn't work because vbulletin shows the database error before this code can be executed
if ($db->mysql_errno() == 1062) {
standard_error('File already uploaded!');
}
}Thanks in advance.

Frexter

Lynne
02-09-2013, 06:37 PM
What 'default' database error? Aren't you getting it emailed to you so you may see the full error?

kh99
02-09-2013, 06:41 PM
I think if you call $db->hide_errors() before then query, then $db->show_errors() when you're done, it will turn off the vbulletin error reporting.

Fraxter
02-09-2013, 06:42 PM
For sure i can see the complete database error. But i want to "hide" the database error and display my own error message. But only if the mysql error number is 1062, which is for duplicate key entrys.

--------------- Added 1360439313 at 1360439313 ---------------

Thanks kh99, with the hide_errors() function it works. =)

kh99
02-09-2013, 06:51 PM
If you only want to detect duplicates, maybe you can use INSERT....IGNORE to cause it to ignore duplicates, then check the number of rows to see if it affected 1 or 0 rows (but I haven't tried it so I'm not sure if it works). If it works then you could remove the hide and vbulletin would handle any other errors.

Fraxter
02-09-2013, 07:01 PM
The idea is much better and it works. Thanks again kh99. :)