mojtabakh18
March 3rd, 2017, 14:27
سلام برای ارتباط دادن دیتابیس با پروژه هام در php از کلاس زیر استفاده می کنم
class Database{
private $connection;
public function __construct()
{
global $config;
$host = $config['db']['host'];
$user = $config['db']['user'];
$pass = $config['db']['pass'];
$name = $config['db']['name'];
$this->connection = new mysqli($host, $user, $pass, $name);
$this->connection->query("SET NAMES utf8");
}
public function query($sql)
{
$result = $this->connection->query($sql);
$records = array();
if ($result->num_rows == 0) {
return null;
}
while ($rows = $result->fetch_assoc()) {
$records[] = $rows;
}
return $records;
}
public function first($sql)
{
$records = $this->connection->query($sql);
if ($records == null) {
return null;
}
return $records[0];
}
public function connection()
{
return $this->connection;
}
public function close()
{
$this->connection->close();
}
}
تمامی متد ها به خوبی کار می کنه به غیر از متد first کسی میدونه علتش چیه؟؟
ممنون
class Database{
private $connection;
public function __construct()
{
global $config;
$host = $config['db']['host'];
$user = $config['db']['user'];
$pass = $config['db']['pass'];
$name = $config['db']['name'];
$this->connection = new mysqli($host, $user, $pass, $name);
$this->connection->query("SET NAMES utf8");
}
public function query($sql)
{
$result = $this->connection->query($sql);
$records = array();
if ($result->num_rows == 0) {
return null;
}
while ($rows = $result->fetch_assoc()) {
$records[] = $rows;
}
return $records;
}
public function first($sql)
{
$records = $this->connection->query($sql);
if ($records == null) {
return null;
}
return $records[0];
}
public function connection()
{
return $this->connection;
}
public function close()
{
$this->connection->close();
}
}
تمامی متد ها به خوبی کار می کنه به غیر از متد first کسی میدونه علتش چیه؟؟
ممنون