How the heck can one use mysqli to grab the defined field length for
all columns?
I can't believe mysqli_field_len() does not exist, and I don't find a
new function to grab the defined length (sure, the data length can be
fetched, but I don't care about that, for example I need the length
255 from varchar(255) or 30 from varchar(30)
It's part of the result set. See MySQLi_result->lengths() or
mysqli_fetch_lengths($result).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
Try the following:
<?php
$fwidths = array();
$link = mysqli_connect('host','user','password','db');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",mysqli_connect_error());
exit();
}
$result = mysqli_query($link,"SELECT * FROM table");
if ($result) {
$fnr = mysqli_num_fields($result);
while ($fnr --) {
$metadata = mysqli_fetch_field_direct($result, $fnr);
$fwidths[$metadata['name']] = $metadata['length'];
}
mysqli_free_result($result);
}
else {
printf("Query failed: %s\n",mysqli_error($link));
}
if (count($fwidths)) print_r($fwidths);
else echo "$fwidths is empty\n";
?>
I think $fwidths['column-name'] should then contain column-width as
defined in the database schema, although I didn't actually test this.
Rgds
Denis McMahon