TinyMVC: PDO & UTF-8 Character Set

When setting up the initial model for a TinyMVC project, I got the following error:

Message: Can’t connect to PDO database ‘mysql’. Error: SQLSTATE[HY000] [2019] Can’t initialize character set UTF-8 (path: /usr/share/mysql/charsets/)

After looking in /path/to/tinymvc/sysfiles/plugins/tinymvc_pdo.php I noticed the following on line 95:

    if(empty($config['charset']))
        $config['charset'] = 'UTF-8';

Since nothing appeared wrong, I did a quick Google search and found this bit of information:

Just tried your recommendation on the other server with php 5.3.6 and it worked with utf8 versus utf-8. Just to double check i tried it again with utf-8 and that didn’t work

So, armed with that knowledge, I updated /path/to/tinymvc/sysfiles/plugins/tinymvc_pdo.php to read as:


    if(empty($config['charset'])) {
        $config['charset'] = 'UTF8';
    }

Bingo! After saving the file and refreshing, the error was gone!

Nick

HTML and JavaScript: Safari and Loading Files

Today I experienced an odd issue with Safari. It appears as though the HTML attribute defer=”defer” is not translated by Safari. Below are two examples of code. The former was what worked in every major browser except Safari. The latter works in all browsers that I have tested.

<script type=”text/javascript” defer=”defer” src=”/js/file2.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file3.js”></script>
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”></script>
<script type=”text/javascript” defer=”defer” src=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file1.js”></script>

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”></script>
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file1.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file2.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file3.js”></script>

The reason that the former was in that order was because of the way that Zend loads files via prependFile() and appendFile(). Using the proper combination of the two functions, I was able to get them into the desired order.

Nick

PHP: cURL and htpasswd [apache auth]

After spending literally all afternoon working on it, here an example of the code I finally got to work!

curl_setopt( $this->_curlHandle, CURLOPT_URL, ‘site.com/password-protected’ );
curl_setopt( $this->_curlHandle, CURLOPT_USERPWD, ‘username:password’ );
curl_setopt( $this->_curlHandle, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $this->_curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
$result = curl_exec($this->_curlHandle);

I have bolded the part that was the culprit! I hope this saves you time [and your company money ;-) ].

Nick

PHP: sample output of integer-based array after serialize()

I was hoping to avoid writing a script to give me this basic information, but alas, I did not.

There are plenty of examples of serializing string-based arrays, but I found none with integers — granted I did not waste much time searching. Anyway, below is the PHP code, the the appropriate output.

<?php echo serialize(array(1,2,3)); ?>

a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}

Nick

mysqli_num_rows() functionality

Warning: mysqli_num_rows() [function.mysqli-num-rows]: Function cannot be used with MYSQL_USE_RESULT

Does this error look familiar? Yeah, weird that even though you are using mysqli_, it says MYSQL_; trust me, I know. Instead of using mysqli_use_result(), try mysqli_store_result(). Problem sloved.

Nick