0

I'm editing the question::: What is wrong with my save function.It's give a "Call to a member function bind_param() on a non-object error" in second line in save method.

public function __construct()
{   
$this->lastResult=null;
global $loader;
$this->_dbConfig = $loader->getConfig('database');

if(Env == 'development')

{
    $dbcon=$this->_dbConfig['local'];

}
else
{
    $dbcon=$this->_dbConfig['global'];

}
$con=mysqli_connect($dbcon['servername'],       $dbcon['username'],$dbcon['password'],$dbcon['databasename']);

$this->mysqli=$con;
if (mysqli_connect_errno())
{
throw new Exception("Failed to connect to MySQL: " . mysqli_connect_error(), 1);
}
}
                                                                       //This is my save method for inserting value dynamically
public function save($data,$data1)
{ 
$insert=$this->mysqli->prepare("insert into $this->tbl1(test1,test2)      values (?,?)");//giving error in this line.
$insert->bind_param('is',$data,$data1);
$insert->execute();
$insert->close();

}

  • It seems that this is a method, so I think you want to use: `$this->mysqli->prepare` – Rizier123 Mar 03 '15 at 06:35
  • Please show enough code to reproduce the problem. – merlin2011 Mar 03 '15 at 06:36
  • `$mysqli` is out of scope – Kevin Mar 03 '15 at 06:38
  • Thanks for you comment.After using "$this->mysqli->prepare" its giving Undefined property: error. –  Mar 03 '15 at 06:52
  • Well, where *do* you define the `$mysqli` variable?! – deceze Mar 03 '15 at 06:54
  • I'm using $mysqli for connecting to databae. @deceze –  Mar 03 '15 at 08:43
  • In my constructor i've define $mysqli. i'm using $this->mysqli now .And it is not giving error.now next line giving "Call to a member function bind_param() on a non-object" error.What its mean? –  Mar 03 '15 at 08:46
  • In my constructor I'm using this $con=mysqli_connect($dbcon['servername'], $dbcon['username'],$dbcon['password'],$dbcon['databasename']); $this->mysqli=$con; –  Mar 03 '15 at 08:51

0 Answers0