Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

При получении getLastId();


Recommended Posts

При получении getLastId() из другой функции первое значение у меня выходит NULL  !!

К примеру вот в данной функции я передаю в переменную полученный id

	public function addProductRelated(&$product_id_related, &$dataRelated) {


			
	$sql = '';

		$sql = 'INSERT INTO `' . DB_PREFIX . 'product` SET ' . $sql;
		$this->db->query($sql);
		
		$product_id_related = $this->db->getLastId();	

		if (isset($this->setting['product_store'])) {
			foreach ($this->setting['product_store'] as $store_id) {
				$this->db->query('INSERT INTO `' . DB_PREFIX . 'product_to_store` SET product_id = \'' . (int)$product_id_related . '\', store_id = \'' . (int)$store_id . '\'');
			}
		}
		
		if(!$product_id_related) return FALSE;
		
		$sql = '';

		if(isset($this->field_caption['_NAME-RELATED_'])) {
			$sql .= ' name = REPLACE(\'' . $this->db->escape($dataRelated[$this->field_caption['_NAME-RELATED_']]) . '\', \'"\', \'"\'),';
		}

$this->product_id_related_new = $product_id_related; //вот имеено тут !!!!!!!!
			return true;
			
	}
	

B и вывожу его в другой функции  !
 

 
$get_product_id_related = $this->product_id_related_new;

echo "<pre>";		
var_dump($get_product_id_related);	
echo "</pre>";

и получаю результат  !
image.thumb.png.afd005de18ab7fe45f73e04437857cf6.png

Первое значение у меня NULL 
Но если я буду выводить данный getLastId() в самой функции то проблем у меня нет  !

Edited by Sabufer
Link to comment
Share on other sites


1 минуту назад, spectre сказал:

ну а 

$this->product_id_related_new;

объявлен?

Всмысле обьявлен типо так что ли ?? 
$this->product_id_related_new = $product_id_related; //вот имеено тут !!!!!!!!

Link to comment
Share on other sites


2 часа назад, spectre сказал:

 

как-то так

 

и вы ошибочно полагаете что я вам что-то должен

 

вот это понятный пример 

class Test
{
  public $some_property = '123';
}

$obj = new Test;
var_dump( $obj->some_property )

class Test
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.