如何在PHP中动态创建具有多个字段的表

$dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
      die('Could not connect: ' . mysql_error());
    }

    echo 'Connected successfully<br />';



$name_of_field="id_student";


function field_dynamic($field_num,$field_name){

    for($i=1;$i<=$field_num;$i++){

        if($i!=$field_num){

        $field[$i]="".$field_name."_".$i." VARCHAR(5) NOT NULL,"."";

        }else{

        $field[$i]="".$field_name."_".$i." VARCHAR(5) NOT NULL";

        }

    }
    return $field;
}

$num=13;

$sql_mathematic = "CREATE TABLE mathematic(". 

            field_dynamic($num,$name_of_field).")";

        mysql_select_db("adrian");
        $retval_mathematic = mysql_query( $sql_mathematic, $conn );

        if(! $retval_mathematic )
            {
              die('Could not create table: ' . mysql_error());
            }

            echo "Table created successfully
";

its not working:

Connected successfully
Could not create table: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

Please help me.

THIS IS A BAD IDEA. I MEAN, REALLY, DON'T DO IT. SERIOUSLY, IT WILL SNEAK UP ON YOU AND STAB YOU IN THE BACK

Down-vote this answer if you must, but it is the right answer.

(This would accomplish what you are talking about, but you shouldn't use it.

for($i=1;$i<=$field_num;$i++){
    $field[$i]="".$field_name."_".$i." VARCHAR(5) NOT NULL";

}
return implode(',',$field);

) (I can't help it... bugs... if I see them...)