将php字符串插入mysql

I would like to into a string into mysql and understand I have to explode the string into an array before it can be inserted.

How would I write the PHP object oriented code to insert the string?

I have two variables:

$id = "Apple"    and    $product = "Pie, Candy"

This is what I would like the database to look like:

ID          Product
---         -------
Apple       Pie
Apple       Candy

This is what I have written so far in my code:

$id = "Apple";
$product = "Pie, Candy";
$product_arr = explode(", ",$product);

if (is_array($product_arr)) {
    $sql = "INSERT INTO table1 (id, product) VALUES ";
    $value_arr = array();

    foreach($product_arr as $row) {
        $prdct = mysql_real_escape_string($row[0]);
        $value_arr[] = "('$id','$prdct')";
    }
    mysqli_query($conn,$sql);
}

You can try this

$id = "Apple";
$product = "Pie, Candy";
$product_arr = explode(", ",$product);
$len = count($product_arr);

for($i=0;$i< $len;$i++){
    $product = $product_arr[$i];
    $abc = "INSERT INTO table1 (id, product) VALUES "."('$id','$product')";
    if ($con->query($abc) === TRUE) {
    }
    else
    {
        //echo "Error: " . $abc . "<br>" . $con->error;
    }
}

Output