Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 2nd, 2007, 12:20 PM
Registered User
 
Join Date: Jan 2007
Location: Sheffield, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beg. PHP 5 > Ch. 11 - fetch_field.php

Yet something else that doesn't work in this book! Although this time it isn't the book's fault.

At the bottom of p.430 it mentions that the max_length property of the returned object from mysql_fetch_field() always returns 0. I submitted that a s bug 'cos it's still the same in MYSQL 5.1.14.

Apparently that function has been deprecated. We should now use the SQL 'SHOW COLUMNS FROM table' or query the INFORMATION_SCHEMA.COLUMNS table.

Here's my version of fetch_field.php......

<?php
include_once "./common_db.inc";

$link_id = db_connect();
$query = "SELECT column_name, column_type, is_nullable, column_key, extra ";
$query .= "FROM INFORMATION_SCHEMA.COLUMNS ";
$query .= "WHERE table_name = 'user' AND table_schema = 'sample_db'";
$result = mysql_query($query);

if (!$result) {
    error_message(sql_error());
}

while ($query_data = mysql_fetch_array($result)) {
    echo $query_data["column_name"];

    echo " - " . $query_data["column_type"];

    if ($query_data["is_nullable"] == "NO") {
        echo " not_null ";
    } else {
        echo " null ";
    }

    if ($query_data['column_key'] == "PRI") {
        echo " primary_key ";
    } else if ($query_data['column_key'] == "UNI") {
        echo " unique ";
    } else if ($query_data['column_key'] == "MUL") {
        echo " key ";
    }

    if ($query_data["extra"]) {
        echo " " . $query_data["extra"] . " ";
    }

    echo "<br>";
}
?>




Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 5, Wrox, CH 7 navigator.php Jon_ BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 August 24th, 2008 01:13 PM
does not work register.php in ch 11 begining php5 tanvir_math BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 February 7th, 2007 05:03 PM
Beg apache, php, MYSQL need some help dreadhead BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 December 20th, 2004 11:37 PM
Ch. 12 userviewer.php -> modify Tachyon BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 May 18th, 2004 12:38 PM
Ch. 1: PHP Installation Troubles: php3 vs php manjito BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 June 12th, 2003 03:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.