Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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>";
}
?>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.