Ok trying to convert to the mysqli protocols. Having issues.

Under mysql I've always connected to the database in an included connect file. I tried to just convert the connect file to mysqli object oriented style and then convert the various mysql statements in my programs to the mysqli object equivalents of the mysql statements.

here is the connect file (minus the values for the database variables):

$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}

Here is the first of dozens of statements which didn't work.

function configs($shop){
global $cnfig;
$query="select cvar,cval from configs where shop='".$shop."' order by cvar ASC";
$result=$mysqli->query($query);
while ($row = $result->fetch_object){
$cnfig[$row->cvar]=$row->cval;
}
}

This results in the error: Call to a member function query() on a non-object

I totally don't understand because I followed the exact format shown in the php docs. What did I miss?:eek:

    The variable [font=monospace]$mysqli[/font] isn't defined inside your [font=monospace]config()[/font] function.

      So are you saying that I will have to add a global $mysqli reference to every single function and subroutine in every program?

        Only if your program is so poorly designed that you've got database queries in every function in every program instead of in only one part.

          I see. It wasn't an issue in the past. Ok Thanks.

            Write a Reply...