<?php
$categoria = new Categoria("teste");
echo cadastrarCategoria($categoria);
function cadastrarCategoria($categoria) {
$categoriaPai = $categoria->CategoriaPai ?? 'null';
$query = "INSERT INTO categoria (nome, categoria_idcategoria) values ('{$categoria->Nome}', {$categoriaPai})";
return $query;
}
class Categoria
{
public $Nome;
public $CategoriaPai;
function __construct()
{
$this->Nome = $a[0];
$this->CategoriaPai = $a[1];
}
}
PD9waHAKJGNhdGVnb3JpYSA9IG5ldyBDYXRlZ29yaWEoInRlc3RlIik7CmVjaG8gY2FkYXN0cmFyQ2F0ZWdvcmlhKCRjYXRlZ29yaWEpOwoKZnVuY3Rpb24gY2FkYXN0cmFyQ2F0ZWdvcmlhKCRjYXRlZ29yaWEpIHsKICAgICRjYXRlZ29yaWFQYWkgPSAkY2F0ZWdvcmlhLT5DYXRlZ29yaWFQYWkgPz8gJ251bGwnOwogICAgJHF1ZXJ5ID0gIklOU0VSVCBJTlRPIGNhdGVnb3JpYSAobm9tZSwgY2F0ZWdvcmlhX2lkY2F0ZWdvcmlhKSB2YWx1ZXMgKCd7JGNhdGVnb3JpYS0+Tm9tZX0nLCB7JGNhdGVnb3JpYVBhaX0pIjsKICAgIHJldHVybiAkcXVlcnk7Cn0KCmNsYXNzIENhdGVnb3JpYQp7CiAgICBwdWJsaWMgJE5vbWU7CiAgICBwdWJsaWMgJENhdGVnb3JpYVBhaTsKCQogICAgZnVuY3Rpb24gX19jb25zdHJ1Y3QoKSAKICAgIHsgCiAgICAgICAgJGEgPSBmdW5jX2dldF9hcmdzKCk7CiAgICAgICAgJHRoaXMtPk5vbWUgPSAkYVswXTsKICAgICAgICAkdGhpcy0+Q2F0ZWdvcmlhUGFpID0gJGFbMV07CiAgICB9Cn0g