Today I learned about PHP parse_str. Worth checking out too are the related functions such as http_build_query.
Tag Archives: php
PHP: The Right Way
Over on the ProgClub programming list Justin pointed out PHP: The Right Way which is definitely on my reading list.
100% Apache-Compliant REQUEST_URI for IIS and Windows
I had a problem with the REQUEST_URI server variable not being available in my PHP app when running under IIS on Windows. I followed these instructions to fix the problem: 100% Apache-Compliant REQUEST_URI for IIS and Windows.
I had to download and install ISAPI Rewrite 3 and Request_URI for IIS 1.1 which I installed into PHP by editing my php.ini file with this line:
auto_prepend_file = C:\Program Files\PHP\request_uri.inc
PHP heredoc syntax
Today I found myself looking up the PHP heredoc syntax. It was cool to learn that you can use {$var} syntax to embed variable data in a heredoc.
Using arrays in PHP
Apparently in PHP 5.4 you can index an array returned from a function as explained here. I learned this today but unfortunately I’m still running PHP 5.3. I also read an article on stackoverflow about how to make an object behave like an array.
MySQL: Error in SQL: Commands out of sync; you can’t run this command now
Today I was programming MySQL via PHP and I received an error “Error in SQL: Commands out of sync; you can’t run this command now”. It turned out the problem was that a previous mulit_query had mysqli_results that hadn’t been freed. This article helped me solve the problem, and now my batch mode SQL processor looks like this:
public function execute_batch( $sql ) {
$this->write_count++;
if ( ! $this->link->multi_query( $sql ) ) {
$this->throw_error( $sql );
}
if ( $this->link->more_results() ) {
do {
$result = $this->link->use_result();
if ( $result instanceof mysqli_result ) {
$result->free();
}
}
while ( $this->link->more_results() && $this->link->next_result() );
}
}
This code executes the SQL batch and then frees any mysqli_results that result from the query batch.
PHP: Create Your Own MVC
A fun video with a walk-through about how to roll your own MVC framework
in PHP: PHP: Create Your Own MVC.
Efficient PHP Debugging In Vim
Found this article today Efficient PHP Debugging In Vim which explains how to setup Vim as a PHP debugger.
There was also Debugging PHP using Xdebug and Notepad++.
PHP Number Base Conversion
I was doing some research into base conversion and so far have found a function, dec2base, which looks like it might come in handy. There’s an online demo of the function.
New bcmod JavaScript function at jsphp.co
I was working on some code the other evening and found myself needing a version of PHP’s bcmod function in JavaScript. It wasn’t already available at jsphp.co so I implemented it and posted about it to the ProgClub programming list.