RE-CREATE TABLE
If you have noticed that 'delete from sometable' is a lot slower than 'drop table; create table' then you are not alone. I finally figured out how to do it on the fly (so you dont have to track 'alter table' commands throughout your code).
<?php
$q="SHOW CREATE TABLE temptable"; $r=mysqli_query($DBlink,$q);
$n=mysqli_num_rows($r); if ($n==1): $w=mysqli_fetch_assoc($r); $createstring=$w['Create Table']; endif;
$q="DROP TEMPORARY TABLE IF EXISTS temptable"; $r=mysqli_query($DBlink,$q);
$q=$createstring; $r=mysqli_query($DBlink,$q);
?>
note: works with all tables (my example uses a temp table)
note: yes, there IS a space in ['Create Table']
This is a very fast way of resetting a table (and resetting its indexes). Hope it helps (it only took me 100 years to figure out!).
Jon
mysqli_num_fields
result->field_count
(No version information available, might be only in CVS)
result->field_count — Obtém o número de campos em um resultado
Descrição
Estilo de procedimento:
int mysqli_num_fields
( object $result
)
Estilo orientado a objeto (propriedade):
result
int$field_count;
mysqli_num_fields() retorna o número de campos do conjunto de resultados especificado.
Valor Retornado
O número de campos do conjunto de resultados
Veja também
Exemplo
Example#1 Estilo orientado a objeto
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = $mysqli->query("SELECT * FROM City ORDER BY ID LIMIT 1")) {
/* determine number of fields in result set */
$field_cnt = $result->field_count;
printf("Result set has %d fields.\n", $field_cnt);
/* close result set */
$result->close();
}
/* close connection */
$mysqli->close();
?>
Example#2 Estilo de procedimento
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = mysqli_query($link, "SELECT * FROM City ORDER BY ID LIMIT 1")) {
/* determine number of fields in result set */
$field_cnt = mysqli_num_fields($result);
printf("Result set has %d fields.\n", $field_cnt);
/* close result set */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
Os exemplos acima devem produzir a seguinte saída:
Result set has 5 fields.
User Contributed Notes
mysqli_num_fields
mysqli_num_fields
jcwebb at dicoe dot com
15-May-2007 05:26
15-May-2007 05:26

mysqli_next_result