This is my cat, Gir. Yes, the one from Invader Zim.
php

<?php

// Create empty variables for population
$name = '';
$iddoc = '';
$number = '';
$customer = '';


// Get all clients in our database    
$SQL = "SELECT * FROM customerdb WHERE ID > 0";
$query = mysqli_query($mysqli_conn, $SQL) or error($SQL);
// Check if we have any first
if (mysqli_num_rows($query) > 0) {
    // We do, now set up the vCard
    $vcardname = "VCard.vcf";
    $vcard = fopen($vcardname, "w") or die("Cannot Open file! Check permissions?");

    // Loop through them all, instantiating our own class for scalability
   
    // You may also just drump directly from your database if you wish with SQL,
    // Or use your own class if you have one already

   while ($c = mysqli_fetch_array($query)) {
       $customer = $c['ID'];
       $CCustomer = new customer($customer);
       // Check if the ID exists
       if ($CCustomer->Exists()) {
          // It does, load up some variables
          $number = $CCustomer->getTelephone();
          $email = $CCustomer->getEmail();
          $name = $CCustomer->getName(false);
          $Fname = $CCustomer->getFirstName();
          $Lname = $CCustomer->getLastName();
          $address1 = $CCustomer->getAddress1();
          $address2 = $CCustomer->getAddress2();
          $town = $CCustomer->getTown();
          $postcode = $CCustomer->getPostcode();
          $region = $CCustomer->getRegion();

         // Write the data to the VCF file
         // Checking if any optional data is populated
         fwrite($vcard, "BEGIN:VCARD\r\n");
         fwrite($vcard, "VERSION:3.0\r\n");
         fwrite($vcard, "FN:{$name} (C-{$customer})\r\n");
         fwrite($vcard, "N:{$Lname};{$Fname} (C-{$customer});;\r\n");
         fwrite($vcard, "TEL;TYPE=cell:{$number}\r\n");
         fwrite($vcard, "EMAIL:{$email}\r\n");
         fwrite($vcard, "ADR;TYPE=home:;;{$address1};{$town};{$region};{$postcode};\r\n");
         fwrite($vcard, "END:VCARD\r\n");
     }
  }
  // Download the vCard file
  // Check if it exists first
  if (file_exists($vcardname)) {
      // Open a new browser tab to the file for download
      echo "<meta http-equiv=\"refresh\" target=\"_blank\" content=\"0;url=$vcardname\">";
  }
}
?>