vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   mysql_query error number (https://vborg.vbsupport.ru/showthread.php?t=294938)

Fraxter 02-09-2013 06:18 PM

mysql_query error number
 
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:

PHP Code:

$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 [DATE]1360439313[/DATE] at [TIME]1360439313[/TIME] ---------------

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. :)


All times are GMT. The time now is 11:52 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01059 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete