Skip to content

Instantly share code, notes, and snippets.

/query.php Secret

Created December 18, 2012 23:47
Show Gist options
  • Save anonymous/6db54b4e6eb9d0e133c6 to your computer and use it in GitHub Desktop.
Save anonymous/6db54b4e6eb9d0e133c6 to your computer and use it in GitHub Desktop.
<?php
/*
DROP TABLE IF EXISTS `md5`;
CREATE TABLE `md5` (
`id` int(11) NOT NULL,
`key` varchar(5) NOT NULL,
`bar` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
*/
require_once("idiorm.php");
ORM::configure('mysql:host=localhost;dbname=test');
ORM::configure('username', 'user');
ORM::configure('password', 'user');
$db = ORM::get_db();
$data=array();
for($i=0;$i<=1000;$i++){
$key=base_convert($i, 10,36);
$data[]=array('key'=>$i,'bar'=>$i);
};
echo "Preparing data done";
$row=ORM::for_table('md5')->create()->save_multi($data);
<?php
/*
DROP TABLE IF EXISTS `md5`;
CREATE TABLE `md5` (
`id` int(11) NOT NULL,
`key` varchar(5) NOT NULL,
`bar` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
*/
require_once("idiorm.php");
ORM::configure('mysql:host=localhost;dbname=test');
ORM::configure('username', 'user');
ORM::configure('password', 'user');
$db = ORM::get_db();
for($i=0;$i<=1000;$i++){
$person=ORM::for_table('md5')->create();
$person->key = base_convert($i,10,36);
$person->bar = $i;
$person->save();
};
@tag
Copy link

tag commented Dec 19, 2012

Data being submitted is different. In line 19 of query.php perhaps you mean:

    $data[]=array('key'=>$key,'bar'=>$i);    // value for 'key' changed from original

There are probably a handful of ways to speed up the first one, if it were important. One that comes to mind first is doing the for_table outside the loop, then cloning it. Using Idiorm's pending raw_execute() method might be even faster than both of the methods shown here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment