При импорте вылетает ошибка
Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /import-excel/DataSource.php on line 147
Fatal error: Uncaught Error: Call to a member function execute() on bool in /import-excel/DataSource.php:109 Stack trace: #0 /import-excel/index.php(73): Phppot\DataSource->insert('insert into tbl...', 'ss', Array) #1 {main} thrown in /import-excel/DataSource.php on line 109
Datasource
<?php
/**
* Copyright (C) 2019 Phppot
*
* Distributed under MIT license with an exception that,
* you don’t have to include the full MIT License in your code.
* In essense, you can use it on commercial software, modify and distribute free.
* Though not mandatory, you are requested to attribute this URL in your code or website.
*/
namespace Phppot;
/**
* Generic datasource class for handling DB operations.
* Uses MySqli and PreparedStatements.
*
* @version 2.5 - recordCount function added
*/
class DataSource
{
// PHP 7.1.0 visibility modifiers are allowed for class constants.
// when using above 7.1.0, declare the below constants as private
const HOST = 'localhost';
const USERNAME = '111';
const PASSWORD = '111';
const DATABASENAME = '111';
private $conn;
/**
* PHP implicitly takes care of cleanup for default connection types.
* So no need to worry about closing the connection.
*
* Singletons not required in PHP as there is no
* concept of shared memory.
* Every object lives only for a request.
*
* Keeping things simple and that works!
*/
function __construct()
{
$this->conn = $this->getConnection();
}
/**
* If connection object is needed use this method and get access to it.
* Otherwise, use the below methods for insert / update / etc.
*
* @return \mysqli
*/
public function getConnection()
{
$conn = new \mysqli(self::HOST, self::USERNAME, self::PASSWORD, self::DATABASENAME);
if (mysqli_connect_errno()) {
trigger_error("Problem with connecting to database.");
}
$conn->set_charset("utf8");
return $conn;
}
/**
* To get database results
*
* @param string $query
* @param string $paramType
* @param array $paramArray
* @return array
*/
public function select($query, $paramType = "", $paramArray = array())
{
$stmt = $this->conn->prepare($query);
if (! empty($paramType) && ! empty($paramArray)) {
$this->bindQueryParams($stmt, $paramType, $paramArray);
}
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$resultset[] = $row;
}
}
if (! empty($resultset)) {
return $resultset;
}
}
/**
* To insert
*
* @param string $query
* @param string $paramType
* @param array $paramArray
* @return int
*/
public function insert($query, $paramType, $paramArray)
{
$stmt = $this->conn->prepare($query);
$this->bindQueryParams($stmt, $paramType, $paramArray);
$stmt->execute();
$insertId = $stmt->insert_id;
return $insertId;
}
/**
* To execute query
*
* @param string $query
* @param string $paramType
* @param array $paramArray
*/
public function execute($query, $paramType = "", $paramArray = array())
{
$stmt = $this->conn->prepare($query);
if (! empty($paramType) && ! empty($paramArray)) {
$this->bindQueryParams($stmt, $paramType, $paramArray);
}
$stmt->execute();
}
/**
* 1.
* Prepares parameter binding
* 2. Bind prameters to the sql statement
*
* @param string $stmt
* @param string $paramType
* @param array $paramArray
*/
public function bindQueryParams($stmt, $paramType, $paramArray = array())
{
$paramValueReference[] = & $paramType;
for ($i = 0; $i < count($paramArray); $i ++) {
$paramValueReference[] = & $paramArray[$i];
}
call_user_func_array(array(
$stmt,
'bind_param'
), $paramValueReference);
}
/**
* To get database results
*
* @param string $query
* @param string $paramType
* @param array $paramArray
* @return array
*/
public function getRecordCount($query, $paramType = "", $paramArray = array())
{
$stmt = $this->conn->prepare($query);
if (! empty($paramType) && ! empty($paramArray)) {
$this->bindQueryParams($stmt, $paramType, $paramArray);
}
$stmt->execute();
$stmt->store_result();
$recordCount = $stmt->num_rows;
return $recordCount;
}
}
61-75 index
if (! empty($dateup) || ! empty($filial) || ! empty($tarif) || ! empty($numbsim) || ! empty($phonenumb) || ! empty($dateout) || ! empty($agents)) {
$query = "insert into tbl_info(dateup,filial,tarif,numbsim,phonenumb,dateout,agents) values(?,?)";
$paramType = "ss";
$paramArray = array(
$dateup,
$filial,
$tarif,
$numbsim,
$phonenumb,
$dateout,
$agents
);
$insertId = $db->insert($query, $paramType, $paramArray);
// $query = "insert into tbl_info(dateup,filial,tarif,numbsim,phonenumb,dateout,agents) values('" . $dateup . "','" . $filial . "','" . $tarif . "','" . $numbsim . "','" . $phonenumb . "','" . $dateout . "','" . $agents . "')";
// $result = mysqli_query($conn, $query);
73 index
$insertId = $db->insert($query, $paramType, $paramArray);