Tag Archives: PHP

Limitations of the QuickBooks REST API; A Developer’s Review

This is going to be short and sweet, for now. I started writing this after hitting one too many issues while working with the QuickBooks REST API in PHP. Instead of losing track of them, or convincing myself I imagined them, I decided to jot everything down as I go.

What follows is not a polished article yet. It is more of a running list of oddities, limitations, and outright frustrations I have encountered in both the API and the Web UI. Eventually, I will clean this up and turn it into something more structured, but for now, this is the raw version.

Beyond PHP: VBA Included
The limitations discussed here are inherent to the REST API itself and not to PHP, VBA, python, or any other language. In prior posts, I’ve demonstrated how to connect Access (VBA) to QuickBooks. Thus, everything discussed below is equally application to all VBA solutions (Access, Excel, …) or any other programming language using the REST API.
 
Continue reading

Moving from Microsoft Access to PHP Web Applications, Why?

I’ve been debating about writing such an article for a long, long time now, but with the incessant issues with Access, Microsoft effectively killing Outlook, I believe the time has come to stop beating around the bush on this one.

Today, I wanted to present to you a few of the main reasons why considering a move to Web Application development may be the better choice. I am primarily focusing here on PHP, however most comments below would just as easily apply to .net, … or any other proper web development language.

Okay, let’s dive in!

Moving from Microsoft Access to PHP web applications offers several significant advantages for businesses and developers.
 
Continue reading

PHP Connection To Azure SQL Database

For those of you Web App developers, here’s how you setup PHP so you can work with an Azure SQL Database.

It’s a 3 part process, beyond your actual PHP code:

  • Install the Microsoft ODBC Driver
  • Install the Microsoft Drivers for PHP for SQL Server
  • Configure PHP

Continue reading

Yii2 By Example by Fabrizio Calderelli

I recently used a trial subscription to Packt Publishing and decided to try a number of their books, one of which was Yii2 By Example by Fabrizio Calderelli.

The general concept of this book is excellent.  Fabrizio takes you from basic introduction (installing composer, starting new basic and advanced projects, installing widgets, …) and slowly builds upon each concept chapter to chapter while building a hotel style room reservation system.  You can tell the author clearly knows the subject very well.

Sadly, however, where the book falls apart, especially for any novice developer just trying to get their feet wet with Yii2, is the fact that there are a slew of

  • Mistakes and omissions
    • PHP syntax errors
      • Missing ; at the end of PHP commands
      • Extra parenthesis
      • Yii coding errors
        • Missing use statements in Yii code
        • Missing Namespace statements
        • Incorrect variable names so that they don’t get properly passed between the controller, model and views
    • SQL syntax errors
      • Extra commas
      • Missing clause (without which the commands won’t execute)
  • Images not reflecting what is written in the text
  • Etc.

throughout the book making actually completing the course material impossible.

There are sections where you are told to use a view, but it was never created!  Then in the next section they state “This is how the file … changes” and then you can sometimes backward engineer the file and finish the previous section.  Although I have managed to get around most problems to complete the book, sometimes spending hours to figure out that the author forgot to include a use statement, etc… I still have not managed to complete chapter 6.  Lucky for me, chapter 7 did not continue what was being done in Chapter 6, otherwise that would have been the end of the book for me.

What amazes me, and shows the lack of quality checking by PACKT and the author, is the simple fact that copying the code into a PHP editor instantaneously flags many syntax errors.  So, many of the issues would have easily been spotted just with a simple copy/paste.

All of the above clearly demonstrates that PACKT and the author never truly followed through the book’s content from start to finish themselves to ensure that it was bug free.

I do like the book on it’s whole, but because of the quantity of errors and the target audience, I can’t rate the book any higher than a 4 out of 10!  Had PACKT, or the author, actually done a minimal amount of Quality Assurance this book would be worthy of 9 or 10 without hesitation!!!

PHP – MPDF – Displaying Foreign Characters Properly

I was performing some work to generate PDFs for a client from a system that could have multiple languages (primarily English and French).  Now out of the box, MPDF worked perfectly with English content, but when I tried generating PDFs with French content I would get blanks or ?.

Once again, I will skip over all the various things I tried, but the final solution (in my case at least) was to used the iconv() function to convert the string encoding so MPDF was happy with it.

So, my code became:

$PDFContent= iconv("cp1252", "UTF-8", $PDFContent);

Now combine that with my issue from my previous post PHP – MPDF – HTML contains invalid UTF-8 character(s) and we get:

$PDFContent = iconv("cp1252", "UTF-8", $PDFContent);
$PDFContent = mb_convert_encoding($PDFContent, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($PDFContent);

So now, with 2 lines of code, we deal with the error and ensured that French accents get handled properly when generating PDFs. You have to love MPDF and PHP!

PHP – MPDF – HTML contains invalid UTF-8 character(s)

I was doing some PHP work for a client which involved using MPDF to generate a PDF on the fly.  On my test server, everything worked perfectly.  Yet, when I ran the code on the production server, I kept getting:

HTML contains invalid UTF-8 character(s)

I won’t bore you with the various iterations I tried, but the final solution was to insert

$PDFContent = mb_convert_encoding($PDFContent, 'UTF-8', 'UTF-8');

prior to actually writing the content to the PDF file. So you code becomes something along the lines of:

$PDFContent = mb_convert_encoding($PDFContent, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($PDFContent);

Create an Apache Sub-Domain

Not long ago, I was looking information on how to create and configure an Apache sub-domain on my test server.  I found a number of websites covering the subject, but even after editing my httpd.conf file to add the domain and sub-domain entries, the sub-domain would not work!?  So I did more digging and testing and what I found was that the various tutorials and explanations all omitted one crucial element to the puzzle, none of them mentioned that you had to also add a subdomain entry to Windows’ host file! I assumed that since the domain already had an entry, Apache & Windows were smart enough to know that a sub-domain would use the same host entry as the domain, I was wrong! Apparently, Apache & Windows are not that smart, actually they appear to be blatantly stupid!

So the first thing you have to do is edit the httpd.conf file to add the required virtual host entries: 1 for the domain & 1 for the sub-domain


    ServerName www.domain.com
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/websites/www.domain.com"


    ServerName subdomain.domain.com
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/websites/www.domain.com/subdomainFolderName"

But even once this is done, you then have to go and make an entry for both your domain and another for your sub-domain in the Windows Host file.  The values below assume a local test server

127.0.0.1    www.domain.com
127.0.0.1    subdomain.domain.com

Once you make both of these changes, restart your Apache server, and everything should work.  It did for me at least!

PHP Random String Generator

Have you ever need to generate a random string or generate a unique id using PHP. Below is a complete example of how to do so. Simply copy the entire code into a new php page and then open it.

PHP Random String Generator

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>PHP Random String Generator</title>
</head>

<body>
    <?php
    # AUTHOR: 		Daniel Pineault, CARDA Consultants Inc.
    # DATE:			2010-06-25
    # PURPOSE: 		Generate a random string or unique Id
    # COPYRIGHT: 	You are free to use this code as you wish as long as
    #	 			this header is included in the final work.  This is 
    #				provided 'AS IS' and I assume no liability for its
    #				usage.
    #			

    if (empty($_POST)) {
        $UCase   = 1;
        $LCase   = 1;
        $Nbr     = 1;
        $SpecChrs = 1;
        $ExChrs  = "";
        $RandStrLen = 12;
    } else {
        foreach ($_POST as $key => $value) {
            $$key = strip_tags($value); //sanitize provided user entries
        }
        if (empty($UCase)) {
            $UCase = 0;
        }
        if (empty($LCase)) {
            $LCase = 0;
        }
        if (empty($Nbr)) {
            $Nbr = 0;
        }
        if (empty($SpecChrs)) {
            $SpecChrs = 0;
        }
        if (empty($ExChrs)) {
            $ExChrs = "";
        }
        if (empty($RandStrLen)) {
            $RandStrLen = 12;
        }
    }

    $sRandString = "";

    if (isset($GenRndStr)) {
        $s = "";
        $sUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $sLower = "abcdefghijklmnopqrstuvwxyz";
        $sNumbers = "0123456789";
        $sSpecial = "!@#$%^&*()[]{},.;:'/\~-+=|<>";

        if ($UCase == 1) {
            $s .= $sUpper;
        }
        if ($LCase == 1) {
            $s .= $sLower;
        }
        if ($Nbr == 1) {
            $s .= $sNumbers;
        }
        if ($SpecChrs == 1) {
            $s .= $sSpecial;
        }
        if (strlen($ExChrs) > 0) {
            for ($k = 0; $k <= (strlen($ExChrs) - 1); $k++) {
                $s = str_replace((string)$ExChrs[$k], "", $s);
            }
        }

        $sLen = $RandStrLen;

        for ($i = 1; $i <= $sLen; $i++) {
            $sRandString .= $s[Rand(1, strlen($s))];
        }
    }
    ?>
    <h1>PHP Random String Generator</h1>
    <form id="RndStrGen" name="RndStrGen" method="post">
        <table border="0" cellspacing="0" cellpadding="2">
            <tr>
                <td valign="top"><strong>Password Characteristics</strong> </td>
                <td><input type="checkbox" id="UCase" name="UCase" value="1" <?php
                                                                                if ($UCase == 1) {
                                                                                    echo ' checked="checked"';
                                                                                }
                                                                                ?> />
                    Upper Case Characters<br />
                    <input type="checkbox" id="LCase" name="LCase" value="1" <?php
                                                                                if ($LCase == 1) {
                                                                                    echo ' checked="checked"';
                                                                                }
                                                                                ?> />
                    Lower Case Characters<br />
                    <input type="checkbox" id="Nbr" name="Nbr" value="1" <?php
                                                                            if ($Nbr == 1) {
                                                                                echo ' checked="checked"';
                                                                            }
                                                                            ?> />
                    Numbers<br />
                    <input type="checkbox" id="SpecChrs" name="SpecChrs" value="1" <?php
                                                                                    if ($SpecChrs == 1) {
                                                                                        echo ' checked="checked"';
                                                                                    }
                                                                                    ?> />
                    Special Characters (!@#$%^&*()[]{},.;:'/\~-+=|<>)
                </td>
            </tr>
            <tr>
                <td valign="top"><strong>Characters to Exclude</strong></td>
                <td><input type="text" id="ExChrs" name="ExChrs" value="<?= $ExChrs ?>" /></td>
            </tr>
            <tr>
                <td><strong>Password Length</strong> </td>
                <td><input type="text" id="RandStrLen" name="RandStrLen" value="<?= $RandStrLen ?>" /></td>
            </tr>
        </table>
        <p>
            <input type="submit" id="GenRndStr" name="GenRndStr" value="Generate String" />
        </p>
    </form>
    <?php
    if (isset($sRandString)) {
        echo "<p>" . $sRandString . "</p>\n";
    }
    ?>
</body>

</html>