I was working on Keith Palmer Quickbooks PHP API. It all works fine and connects. The example queries return the result in arrays. What I wanted to do is run an mysqli insert statement which would run through the results array and save the records in mysqli table.
Here is my code which get's the records from Quickbooks and save it in mysqli table.
$customers = $CustomerService->query($Context, $realm, "SELECT * FROM Customer");
foreach ($customers as $Customer)
{
//First, we will retrieve the ID, and strip out any spaces/characters.
$id = $Customer->getId();
$str = preg_replace("/[^0-9]/","",$id);
//Insert customer into customer tables.
$sql = "INSERT INTO Customers (CustomerID__kp, CustomerName, CustomerAddress1, CustomerCity, CustomerCounty, CustomerPostcode, CustomerTelephone)
VALUES ('".$str."',
'".$Customer->getFullyQualifiedName()."',
'".$Customer->getBillAddr(0)->getLine1()."',
'".$Customer->getBillAddr(0)->getCity()."',
'".$Customer->getBillAddr(0)->getCountrySubDivisionCode()."',
'".$Customer->getBillAddr(0)->getPostalCode()."',
'".$Customer->getPrimaryPhone(0)->getFreeFormNumber()."'
)
ON DUPLICATE KEY
UPDATE CustomerName = '".$Customer->getFullyQualifiedName()."',
CustomerAddress1 = '".$Customer->getBillAddr(0)->getLine1()."',
CustomerCity = '".$Customer->getBillAddr(0)->getCity()."',
CustomerCounty = '".$Customer->getBillAddr(0)->getCountrySubDivisionCode()."',
CustomerPostcode = '".$Customer->getBillAddr(0)->getPostalCode()."',
CustomerTelephone = '".$Customer->getPrimaryPhone(0)->getFreeFormNumber()."'
";
$conn->query($sql);
}
?>
My question is I get this error:
Fatal error: Call to a member function getFreeFormNumber() on null in C:\qbapi\quickbooks-php-master\docs\
When I run customer queries, the code gets the customers saved in my quickbooks, and save in my mysqli. But for some reason I get the above error.