webERP Forum

Full Version: Warning: mysql_query() expects parameter 2 to be resource, null given
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

SimonRhodes

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?

which script does this occur in?
are you using DBType=mysql or mysqli?

SimonRhodes

(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.

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

SimonRhodes

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.
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.
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.
Yep that would explain it. Hopefully it was as simple as that:-)
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.
>