Category Archives: PHP

PHP Programming

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);

CodeIgniter 1.7 Professional Development – Review

I have done a considerable amount of web development over the years ranging from HTML to MySQL/PHP driven web applications utilizing the power of such things as javascript, AJAX, jQuery and many more…

I finally decided that it was about time for me to get serious and look into a FrameWork to better standardize my work. As such, I purchased a couple books on the matter, one of which was CodeIgniter 1.7 Professional Development by Adam Griffiths (272 pages) and published by PACKT Publishing.

All I can say is in comparison with the ZEND Framework in Action book, this was a real treat! It was easy to read and they started out with the very basics; Installing CodeIgniter!

The book is written in a manner that I found very fluid and the chapters just seems to flow one into the other.

I think this book is a great purchase for any new CodeIgniter developer looking to learn the basic quickly and easily. At +/-300 pages it isn’t too heavy to be intimidating, but does cover a lot of material in a manner you will understand.

I don’t regret this purchase in the least.

ZEND Framework in Action – Review

I will keep this very short and to the point.

I recently purchased a series of books, one of which was:

ZEND Framework in Action by Rob Allen, Nick Lo & Steven Brown, published by Manning with a total of 401 pages.

I can’t quite explain it, but something just doesn’t work. I seem to end up reading 3-4 times the same sections as if I am continually missing some key piece of information to allow me to actually understand and follow?! They cover everything I wanted to learn, but it just doesn’t seem to be complete. It just doesn’t seem to flow like other books I have read.

For instance, I had to go online to find out how to generate the ZEND directory structure, they seem to make a lot of assumption and/or skip over certain basic issues that, in my humble opinion, need to be part of the book to make it complete! I say this as I am also reading another book about CodeIgniter, which makes this one pale in comparison.

Case and point, I have been unable to date, to create a functional version of the helloworld example as explained in chapter 2 of the book! I keep getting errors no matter what I try. This book has ended up being more frustrating than anything else.

I think for a beginner looking to learn from scratch, this book leaves a lot to be desired. I’d keep looking. For an intermediate Zend developer, this book may be more appropriate.

I am still trying to complete the entire book and will post back with a final verdict.

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>