0

I wrote a class to that take array of values and table_name as parameter and inserts values into the respective table. This is working absolutely fine in projects on my linux system. But today I moved a project to a windows laptop and the class is giving error

"No data supplied for parameters in prepared statement."

This is my class:

<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 3/27/17
 * Time: 10:11 PM
 */
namespace MYSQL;
ini_set('display_errors',0);

class Insert
{
    private $table_name;
    private $array;


    //initializing variable and array

    public function  __construct(){
        $this->table_name='';
        $this->array= array();

    }

    /**
     * @set array
     */
    public function setArray($array){

        foreach ($array as $key => $value)
            $this->array[$key]=$value;
    }

    /**
     * @set array
     */
    public function setTableName($table_name){

        $this->table_name=$table_name;
    }

    /**
     * @return array
     */
    public function getArray()
    {
        return $this->array;
    }

    /**
     * @return string
     */
    public function getTableName()
    {
        return $this->table_name;
    }


    public function performTask($con){


        foreach ($this->getArray() as $key=>$value){

            $fields[]=$key;
            $values[]=$value;
            /*
            if(gettype($value)== 'integer')
                $values['i']=$value   ;
            if(gettype($value)== 'string')
                $values['s'] =$value;
            if(gettype($value)== 'double')
                $values['d']=$value;
            */

        }


        $stmt=$con->prepare("INSERT INTO ".$this->getTableName()."(".implode(',',$fields).") VALUES (".implode(',', array_fill(0, count($fields), '?')).")");
        $values = array_merge(array(str_repeat('s', count($values))), array_values($values));
        call_user_func_array(array(&$stmt, 'bind_param'), $values);

        if($stmt->execute()){
            $stmt->close();
            return "Inserted Successfully.";

        }
        else{
            $stmt->close();
            return "Failed to Insert records.";
        }
    }
}

I have seriously gone through all of the questions on this error and have not found any sensible solution yet for my case.

halfer
  • 19,824
  • 17
  • 99
  • 186

0 Answers0