Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.

Archive for April, 2008

mysql running sql files

Posted by chris on April 21st, 2008 Comments(0)

From the MySQL command line use the database your SQL file will be affecting.

use database;

To execute the file.

source /path-to-file/file.sql

I always forget this one.

In SQL ()

slick interfaces with javascript + MooTools + mochaUI

Posted by chris on April 8th, 2008 Comments(0)

Checkout mochaUI I’ve been using it on a new web app I’m building and I’m very impressed with it. The code is very straightforward and the developers of mochaUI have put together some good documentation. It’s based on the MooTools javascript framework.
Creating slick interfaces can be as easy as this:

1
2
3
4
5
6
7
8
9
		document.mochaUI.newWindow({
			id: 1,
			title: 'Add Note',
			content: 'some text is here',
			scrollbars: true,
			modal: false,
			width: 400,
			height: 200 
		});
In JavaScript and Ajax ()

Convert a PHP Object to an Array

Posted by chris on April 8th, 2008 Comments (6)

I’m really surprised that PHP 5 does not have built-in functionality for converting objects into arrays. Basically I had an Ajax function sending me a javascript object in JSON format to my PHP method. My method was already setup to handle an array, so after decoding the JSON into a PHP object and passed the object into this function.

1
2
3
4
5
6
7
8
9
	function objectToArray($object)
	{
		$array=array();
		foreach($object as $member=>$data)
		{
			$array[$member]=$data;
		}
		return $array;
	}

The problem with this method is that it will only move public variables into the array. Anything that is private cannot be accessed. You can try type casting your PHP 5 object to an array.

$array = (array) $this;

When I did this I got some really strange characters in the array. It does not seem that there is an easy way to convert a PHP 5 object to an array. Your best bet is to write a custom function that either converts your objects variables into array elements or if you are connecting to a database, just return the result set that builds the object in array form.

In Programming (, , )