Its based on reference, so you need to have attribute reference set in product attributes.
I'm using this, should help you.
$query= $db2->prepare("Select ps_product.id_manufacturer AS manuid,ps_product_attribute.reference AS REF,ps_stock_available.quantity AS QTY from ps_product LEFT JOIN ps_product_attribute on ps_product_attribute.id_product=ps_product.id_product LEFT JOIN ps_stock_available on ps_stock_available.id_product_attribute=ps_product_attribute.id_product_attribute");
And here is update.
$query = $db2->prepare("UPDATE ps_product_attribute LEFT JOIN ps_stock_available on ps_stock_available.id_product_attribute=ps_product_attribute.id_product_attribute LEFT JOIN ps_product on ps_product_attribute.id_product=ps_product.id_product SET ps_stock_available.quantity = '".$newqty."' WHERE ps_product_attribute.reference = '".$indeks."'");