vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Need php5 expert (https://vborg.vbsupport.ru/showthread.php?t=319414)

kylek 07-09-2015 07:23 PM

Need php5 expert
 
I have an addon product that worked in php4 but we upgraded to php5 and most of it works except for 1 error showing at top of page. I have no knowledge of php but am trying to learn.

This is the error we are getting:

HTML Code:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean  given in /home/xxxx/xxx/pickem/includes/header.php on line  122
This is line 122 header.php:

HTML Code:

if (mysql_num_rows($query)) {
Using http://phpcodechecker.com/ I checked line 119 to line 129:

HTML Code:

$sql = "select * from " . $db_prefix . "users where userID = " . $user->userID;
$query = mysql_query($sql);

if (mysql_num_rows($query)) {
    $result = mysql_fetch_array($query);
        $template_name = $result['template_name'];
}

if (!empty($_POST['template_name'])) $template_name = $_POST['template_name'];

?>

Results:
Warning: There are 3 functions in your code that have been deprecated in the current version of PHP :
mysql_fetch_array()
mysql_num_rows()
mysql_query()

Any ideas on what may work?

kh99 07-09-2015 07:31 PM

I'm not a php5 expert. But, I see that mysql_query() can return FALSE in the case of an error, and since the error message says that $query is a boolean, I'd assume that's what's happening. You could just check for that in the 'if', like maybe:
Code:

if ($query !== FALSE && mysql_num_rows($query)) {
but I don't know what the error would be or what you would want to do in that case, so that may or may not be the way to handle it.

The mysql interface has been deprecated so you should change to one of the other interfaces, but you can ignore that for now.

ETA: Actually, if that plugin is depending on the database connection that vbulletin opens, and you've changed to using mysqli in the config.php, then the error could be that there's no database connection. In that case what you probably want to do is rewrite the plugin to use the vbulletin database functions (which isn't as difficult as it may sound since the functions are named mostly the same as the mysql functions). That will also take care of the deprecated interface issue.

kylek 07-09-2015 07:57 PM

Thank you very much kh99!!

I changed it to what you suggested and the error is gone now.


All times are GMT. The time now is 10:00 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.01031 seconds
  • Memory Usage 1,718KB
  • 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_code_printable
  • (3)bbcode_html_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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