Page 1 of 1

what's wrong with this code

Posted: Sun Sep 28, 2008 3:50 pm
by nagileon
Hi there
I have a problem wit this script.
For some reason it doesn't return any values.
I'm running the script:
root@ubuntu-jfs:~# php script.php

The output of the script is always:
microtime 1222634669.82
number_of_tablies
database: tap
tables:
total records:
Write rows per sec: 0
Reads rows per sec: 0 sec.

I'm not very good in PHP I'm just trying to run a benchmark to establish what is the mysql performance on different types of file systems.

Please help if you can.
Regards
Pete

Code: Select all

 
 
 
#!/usr/bin/php
<?
$database_name = 'tap';
$number_of_tables = $argv[1];
$number_of_records = $argv[2];

mysql_connect("localhost","root","madmin");
$x=1;
for ($i=1; $i<=$number_of_tables; $i++) {
echo $i;
$result = mysql_query("CREATE TABLE $database_name.table_$i (id INT NOT NULL, c BLOB not null) engine=innodb") or die("Invalid query: " . mysql_error());
};

$t_temp=microtime(1);
for ($j=1; $j<=$number_of_records; $j++)
{
$i=rand(1,$number_of_tables);
$result1 = mysql_query("INSERT INTO $database_name.table_$i (id,c) VALUES ('$j',repeat('0',4000))") or die("Invalid query: " . mysql_error());
}

$t_write_row=$number_of_records/(microtime(1)-$t_temp);

$t_temp=microtime(1);
for ($i=1; $i<=$number_of_tables; $i++) {
$result1 = mysql_query("SELECT count(*) FROM $database_name.table_$i where c='test'" ) or die("Invalid query: " . mysql_error());
};
$t_read_row=$number_of_records/(microtime(1)-$t_temp);

echo "microtime ".
$t_temp. "\n";
echo "number_of_tablies ".
$argv[1]. "\n";
echo "database: ".
$database_name . "\n";
echo "tables: ".
$number_of_tables.
"\n".
"total records: ".
$number_of_records.
"\n".
"Write rows per sec: ".
$t_write_row.
"\n".
"Reads rows per sec: ".
$t_read_row.
" sec.\n";

#echo mysql_result($result,0);
?>

Re: what's wrong with this code

Posted: Sun Sep 28, 2008 4:57 pm
by panic!
#echo mysql_result($result,0);

that might be it? the pound/hash sign...try without anyway.

Re: what's wrong with this code

Posted: Sun Sep 28, 2008 5:26 pm
by alex.barylski
I'm pretty sure the # is just another way to comment code in PHP...I never use it but have seen it used countless times.

Re: what's wrong with this code

Posted: Sun Sep 28, 2008 5:36 pm
by nagileon
After I unhashed the line: echo mysql_result($result,0);
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /root/script.php on line 48
:(