Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Warning: mysql_query() expects parameter 2 to be resource, null given
02-21-2015, 04:55 AM,
#1
Warning: mysql_query() expects parameter 2 to be resource, null given
Last year I started to setup webERP 4.11.3, but only in the past few weeks have I really got stuck in.

Today I upgraded to 4.12.2 and ever since then I keep getting loads of errors messages like

Warning: mysql_query() expects parameter 2 to be resource, null given in /home/weberp/public_html/includes/ConnectDB_mysql.inc on line 202

Warning: mysql_query() expects parameter 2 to be resource, null given in /home/weberp/public_html/includes/ConnectDB_mysql.inc on line 203

Warning: mysql_query() expects parameter 2 to be resource, null given in /home/weberp/public_html/includes/ConnectDB_mysql.inc on line 207

Warning: mysql_query() expects parameter 2 to be resource, null given in /home/weberp/public_html/includes/ConnectDB_mysql.inc on line 208

Looking at the code, parameter 2 should be a global variable which is a pointer to the mysql connection.

The connection to the database is working because most of the system is working.

Any ideas?

Reply
02-21-2015, 06:21 AM,
#2
RE: Warning: mysql_query() expects parameter 2 to be resource, null given
which script does this occur in?
are you using DBType=mysql or mysqli?
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply
02-21-2015, 06:47 AM, (This post was last modified: 02-21-2015, 06:51 AM by SimonRhodes.)
#3
RE: Warning: mysql_query() expects parameter 2 to be resource, null given
(02-21-2015, 06:21 AM)phil Wrote: which script does this occur in?
are you using DBType=mysql or mysqli?

Thank you for the quick reply.

DBType=mysql

It happens in many scripts, mainly to do with the GL

eg

GLTrialBalance.php
GLProfit_Loss.php

before you have even selected a period or any accounts.

Reply
02-21-2015, 10:56 AM,
#4
RE: Warning: mysql_query() expects parameter 2 to be resource, null given
Well this is an odd ball one - I can't repeat it. Would it be possible to take a look at your set up - if you could email me details to login to your set up would be keen to figure this out.
thanks
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply
02-21-2015, 07:46 PM,
#5
RE: Warning: mysql_query() expects parameter 2 to be resource, null given
I had a look at the code this morning and found that ConnectDB_mysql and ConnectDB_mysqli are different.
ConnectDB_mysql was missing global $db in each function.
I have updated the script ConnectDB_mysql and emailed a copy to Phil for him to review.
Reply
02-21-2015, 08:25 PM,
#6
RE: Warning: mysql_query() expects parameter 2 to be resource, null given
This still seems weird to me ...

If you look at:

http://sourceforge.net/p/web-erp/code/HE..._mysql.inc

You can see that the ConnectDB_mysql.inc does have all the functions changed to use the global $db without the parameter - and it was like this with the release of 4.12 and subsequent releases - so must be something that messed up on the upgrade somehow? Would be keen to understand how it happened just in case it might be a trap we could avoid for others.
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply
02-22-2015, 02:08 AM, (This post was last modified: 02-22-2015, 02:18 AM by TurboPT.)
#7
RE: Warning: mysql_query() expects parameter 2 to be resource, null given
Not saying this has occurred, but it "sounds like" a manual update might have been performed?

For example: perhaps only selective files from the update may have been copied instead of using the entire update? ... or maybe some old files were copied from an old version to the new version that "clobbered" new[er] files?

Just some possibilities.

@Simon: IF this happens to be the case, don't be shy, you would not be the first! Please let us know so that we don't "troubleshoot for nothing".
A long time ago I did some "selective updates" [not with webERP, but another application], trying to keep/maintain our custom, locally applied updates. I ended up having to update to the full package, and then manually-merge the custom changes back into the new update afterwards. Basically, it was TOO much pain trying to keep specific files between various updates without having errors or some other trouble.
Reply
02-22-2015, 06:03 AM,
#8
RE: Warning: mysql_query() expects parameter 2 to be resource, null given
Yep that would explain it. Hopefully it was as simple as that:-)
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply
02-22-2015, 09:55 AM,
#9
RE: Warning: mysql_query() expects parameter 2 to be resource, null given
Simon figured it out.... missing:

global $db;

statements ...
It was me of course... I must have got called away mid script.

Committing to SVN now...

On 21/02/15 23:54, Simon Rhodes wrote:
>
> Hi Phil,
>
> Line 201 of ConnectDB_mysql.inc
>
> function DB_Txn_Begin(){
>
> mysql_query("SET autocommit=0",$db);
>
> mysql_query("START TRANSACTION",$db);
>
> }
>
>
> And
> Line 213 of ConnectDB_mysqli.inc
>
> function DB_Txn_Begin(){
>
> global $db;
>
> mysqli_query($db,'SET autocommit=0');
>
> mysqli_query($db,'START TRANSACTION');
>
> }
>
>
>
> The global $db; is the missing statement in many functions.
>
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)