求:循环往mysql 数据库插入10000条记录的php代码

希望大侠,把整个程序写完整了,我不会php,呵呵
mysql 数据库 localhost,密码 123456 ,stu数据库中的表是xuesheng(name varhcar(6),id int,sex char,age smallint)
我希望,往xuesheng 这个表中,循环插入 10000 条记录,数据用random() 函数产生。。。。 或者,发到我邮箱 [email protected]

SQL:
CREATE DATABASE /*!32312 IF NOT EXISTS*/`stu` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `stu`;

/*Table structure for table `xuesheng` */

DROP TABLE IF EXISTS `xuesheng`;

CREATE TABLE `xuesheng` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(6) NOT NULL,
`sex` varchar(6) NOT NULL,
`age` smallint(2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CODE:
<?php
/*
coded by Yushine, 2011-10-1 12:47
*/

$config = array();
$config['host'] = 'localhost';
$config['user'] = 'root';
$config['dbpass'] = 'root';
$config['dbname'] = 'stu';

$con = mysql_connect($config['host'], $config['user'], $config['dbpass']);
mysql_query("set names 'UTF8'");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
mysql_select_db($config['dbname']);
for ($i=1; $i<=10000; $i++)
{
insert();
}
}

function insert()
{
$name = 'name'.rand();
$sex = array("男","女");
$rand_sex = $sex[array_rand($sex,1)];
$age = rand(10,20);
$sql = "INSERT INTO xuesheng (name, sex, age) VALUES ('".$name."', '".$rand_sex."', ".$age.")";
mysql_query($sql);
}
温馨提示:答案为网友推荐,仅供参考