@fastboot

MySQLi в PHP почему массив в массиве?

602d707929375993831739.png602d6e700ddc6470188130.png
db.php
<?PHP class db
{
	var $link;
	var $query;
	var $error;
	var $result;
	var $data;
	var $fetch;
	
	function connect
	()
	{
		$this->link = new mysqli ( $this->host , $this->login , $this->pass , $this->db );
		#$this->link->query ( 'SET NAMES utf8' );
	}
	
	function close
	()
	{
		$this->link->close();
	}
	
	function run
	( $query )
	{
		$this->query = $query;
		$this->result = $this->link->query ( $this->query );
		$this->error = $this->link->error;
	}
	
	function row
	()
	{
		$this->data = $this->result->fetch_assoc();
	}
	
	function fetch
	()
	{
		while ( $this->data = $this->result->fetch_assoc() )
		{
			$this->fetch = $this->data;
			return $this->fetch;
		}
	}
	
	function stop
	()
	{
		unset ( $this->data );
		unset ( $this->result );
		unset ( $this->error );
		unset ( $this->fetch );
		unset ( $this->query );
	}
}
?>
ping.php
<?PHP

require_once ( "{$_SERVER['DOCUMENT_ROOT']}\admin\class\db.php" );
require_once ( "{$_SERVER['DOCUMENT_ROOT']}\admin\class\ipinfo.php" );

StartScript();

function StartScript
()
{
	$db = new db();
	$db->connect();
	$db->run('SELECT `IP` FROM `devices_ip`');
	
	$array = mysqli_fetch_all  ($db->result) ;
	var_dump ( $array );
}
?>


Хочу получить массив значений из столбца IP в таблице devices_ip как правильно это сделать?
PHP 8.0
  • Вопрос задан
  • 72 просмотра
Решения вопроса 1
@fastboot Автор вопроса
https://www.php.net/manual/ru/mysqli-result.fetch-...
$array = mysqli_fetch_all  ($db->result , MYSQLI_ASSOC) ;
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
Потому что возвращается массив, каждый элемент которого - одна строка результата в виде обычного или ассоциативного массива.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы