In Magento2 I am trying to connect to an external database and table and use the data to update a custom product attribute where the sku' match in both tables. I temporarily put this code in my footer.phtml file as I am just trying. ti do a quick import/population of custom attributes from an external source
I am trying to do the below query. If I remove my query code and just card code a sku and a part id it updates Magento just fine so something about my sql it does not like. I confirmed my credentials are valid for accessing the database
$machine = "xxxxx";
$machineu = "xxxx";
$machinep = "xxx";
$machinedbname = "xxxx";
// Create connection
$conn = mysqli_connect($machine, $machineu, $machinep, $machinedbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$testsql = mysqli_query($conn, "SELECT * FROM tempinfo");
while($row = mysqli_fetch_array($testsql))
{
extract($row);
echo "<p style='color:#ffffff'>test $sku</p><br />";
$_product = $objectManager->create('\Magento\Catalog\Api\ProductRepositoryInterface')->get($sku,true, 0, true);
$_product->setCustomAttribute("part_id", "$part_id");
$_product->save($_product);
}