There is a MySQL function to return the auto-increment ID of the last inserted ID and that is LAST_INSERT_ID. You can also read about Using AUTO_INCREMENT.
Category Archives: Programming
Inserting multiple rows with an insert statement in MySQL
Today I had to double-check the syntax for doing multiple row inserts in a MySQL insert statement, because my first guess at the syntax was wrong. I found this article which explained the syntax which is basically:
INSERT INTO example (example_id, name, value, other_value) VALUES (100, 'Name 1', 'Value 1', 'Other 1'), (101, 'Name 2', 'Value 2', 'Other 2'), (102, 'Name 3', 'Value 3', 'Other 3'), (103, 'Name 4', 'Value 4', 'Other 4');
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.
Compass
Brad brought the Compass CSS Authoring Framework to my attention the other day.
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.
Enabling Server Side Includes (SSIs)
I have some old web content that works using Server Side Includes and I needed to get it functional on a new web server. I found this article How do I enable server-side includes (SSIs) on my site? which had everything I needed to know.
First I needed to add the content type and output filter to the Apache configuration:
AddType text/html .shtml AddOutputFilter INCLUDES .shtml
Then I needed to add the IncludesNoExec option:
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Then I needed to specify the DirectoryIndex:
DirectoryIndex index.shtml index.html
And that was it!
WordPress theme development
Reading about WordPress theme development. Found the anatomy of a WordPress theme.
Announcing Jsrun
Shawn Van Ness and I released Jsrun today. Jsrun is a script runner and suite of utility scripts written in JScript.NET for doing handy things on Windows.
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++.
HTML5 Declaration
This is too easy to forget, you would think. Yet for some reason I still look it up when I need it:
<!DOCTYPE html>