Tuesday, January 23, 2007

Mysql Tip

If you insert a row, and needs it the generated id for subsequent inserts into other tables.. i hope every body would have faced this: Here is the cool and simple example..

CREATE TABLE customers
(custid INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name CHAR(40) UNIQUE);
CREATE TABLE sales
(salesid INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
custid INT UNSIGNED NOT NULL,
prodid INT UNSIGNED NOT NULL);
INSERT INTO customers VALUES (NULL,'Some Company');
SET @custid = LAST_INSERT_ID();
INSERT INTO sales VALUES (NULL,@custid,1234);
...

The value returned by LAST_INSERT_ID() is unique for this connection.

Friday, January 12, 2007

Which way to get the PHP self script name is the fastest?

From the WebDevLogs.com blog today, there's some benchmarking results from Mgcci's look at PHP's methods for grabbing some common data the script's own name. This includes the magic call to __FILE__: The result shows that __FILE__ is the fastest, so use that when you don't have to use any other method to find the script's self. __FILE__ is a built in constant show the location of the running script.

__FILE__;0.000740
$_SERVER["PHP_SELF"];0.001425
$_SERVER["SCRIPT_NAME"];0.001496
$_SERVER["REQUEST_URI"];0.001509
getenv("REQUEST_URI");0.003845
getenv("SCRIPT_NAME");0.003519
getenv("SCRIPT_URL");0.003480