mysqli and mysqli_field_len

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I was migrating a large project from PHP's mysql functions to mysqli
functions. One project relies on mysql_field_len() and I do NOT find a
comparable mysqli_field_len().

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)

Re: mysqli and mysqli_field_len

On 1/10/2011 6:31 PM, DH wrote:
Quoted text here. Click to load it

It's part of the result set.  See MySQLi_result->lengths() or

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: mysqli and mysqli_field_len

On 11/01/11 00:02, Jerry Stuckle wrote:
Quoted text here. Click to load it

Try the following:

$fwidths = array();
$link = mysqli_connect('host','user','password','db');
if (mysqli_connect_errno()) {
  printf("Connect failed: %s\n",mysqli_connect_error());
$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'];
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.


Denis McMahon

Re: mysqli and mysqli_field_len

Quoted text here. Click to load it

Honestly, like this was difficult to find!

Site Timeline