Over a million developers have joined DZone.

Populate MySQL Tables

·
This script in PHP to populate with demo data tables MySQL.
Remove the primary key before run.




Inserir Registros de Teste

Cadastrar Tabela do MySQL com Massa de Testes

Remova chave primáia da tabela, antes de executar

Observe que nem todos os tipos de dados foram contemplados, alguns ficarão como string

Host
Banco
Usuáio
Senha
Tabela
Registros
20) $tam=20; //Caso queira limitar os campos ao máximo de 20 posições if ($j < $nc-1){ switch (mysql_field_type($consulta, $j)){ case 'int': $n=str_pad($n,$tam,'12345679890'); $inscod .= "$n,"; break; case 'real': $r=str_pad($r,$tam,'1234567890'); $inscod .= "$r,"; break; case 'string': $s=str_pad($s,$tam,"abcdefghijklmnopqrstuvxyz"); $inscod .= "$s',"; break; case 'date': $inscod .= "'$d',"; break; case 'datetime': case 'timestamp': $inscod .= "'$dt',"; break; case 'blog': $inscod .= "'$t'"; break; default: $o=str_pad($o,$tam,"abcdefghijklmnopqrstuvxyz"); $inscod .= "'$o',"; break; } }else{ switch (mysql_field_type($consulta, $j)){ case 'int': $n=str_pad($n,$tam,'1234567890'); $inscod .= "$n"; break; case 'real': $r=str_pad($r,$tam,'1234567890'); $inscod .= "$r"; break; case 'string': $s=str_pad($s,$tam,"abcdefghijklmnopqrstuvxyz"); $inscod .= "$s'"; break; case 'date': $inscod .= "'$d'"; break; case 'datetime': case 'timestamp': $inscod .= "'$dt'"; break; case 'blog': $inscod .= "'$t'"; break; default: $o=str_pad($o,$tam,"abcdefghijklmnopqrstuvxyz"); $inscod .= "'$o'"; break; } } } $inscod .=");"; for($r=1;$r<=$registros;$r++){ //echo $inscod; if(!mysql_query($inscod,$conexao)) die ("Erro na inclusão".mysql_error()); } } ?>
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}