Jump to content

Recommended Posts

Hi,

I want to start using mysqli on my site instead of mysql, to take advantage of prepared statements. In my mysql.php file, which holds the connect functions for mysql, I added:

$mysqli = new mysqli("localhost", "user", "pass", "db");

so now there is a class called mysqli, that I use to carry out DB operations (I hope that's how it works anyway).

 

But when I am inside one of my own classes, I cannot access $mysqli to do queries and such like. I get this error:

 

 

Fatal error: Call to a member function query() on a non-object in C:\Inetpub\wwwroot\maxms.net\common.php on line 36

 

 

What simple thing have I missed?

 

Thanks for any help

 

Rob

Link to comment
https://forums.phpfreaks.com/topic/52233-mysqli-within-a-class/
Share on other sites

Here is how I setup my class -- im not giving a lot of code, just the basics of how i setup my class for my site...

<?php
class TURBO extends Templatized{ 

var $db = null;
var $st = null;
var $adv_stats = null;

    var $timeoutSeconds = 120;
    var $numberOfUsers = 0;

function TURBO() {
$this->template_dir = $_SERVER['DOCUMENT_ROOT'] . '/cesite/templates';
$this->compile_dir = $_SERVER['DOCUMENT_ROOT'] . '/cesite/templates_c';
$this->config_dir = $_SERVER['DOCUMENT_ROOT'] . '/cesite/configs';
$this->force_compile = TRUE;
$this->sql_db('localhost', 'user', 'pass', 'database');
}
all of my functions goes above the } such as my function TURBO...
}
?>

 

then in my index.php i have this code to call it.

<?php
require_once('../includes/turbo.php'); 
$turbo =& new TURBO; 
?>

 

then in the rest of my index.php i can use $turbo->blah_blah(); to call my functions...

Link to comment
https://forums.phpfreaks.com/topic/52233-mysqli-within-a-class/#findComment-257699
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.