Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
This is the forum to discuss the Wrox book PHP and MySQL: Create-Modify-Reuse by Timothy Boronczyk, Martin E. Psinas; ISBN: 9780470192429
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 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 Display Modes
  #1 (permalink)  
Old April 16th, 2012, 05:40 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 1 Database Connection

Yes: Trying to modify the database connection constance code to a variable for use with a form filed. Like to change WROX_ prefix to whatever I choose. The constance code to change is
Code:
  ('DB_TBL_PREFIX', 'WROX_')
to some type of a variable. Need to know what change to make to the User object query lines that use the DB_TBL_PREFIX code. Examples of code are most welcome.
Jaguarcat.
Reply With Quote
  #2 (permalink)  
Old April 16th, 2012, 11:55 AM
Authorized User
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I'm understanding what you want to do, there is no need to change the user class object.
If you update the DB_TBL_PREFIX to NEW_DB_, the user class still uses the constant DB_TBL_PREFIX. All you'd have to guarantee is that all your tables in the MySQL database start with NEW_DB_ (or whatever name you choose as long as you define it as DB_TBL_PREFIX).

Hope that helps (and was what you were after).

Best Regards,
Master Yoda
Reply With Quote
  #3 (permalink)  
Old April 24th, 2012, 08:07 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 1 Database Connection

Yes, thank you Master Yoda. You really helped me out with the constant prefix workaround. Can I ask this?
Do I need now to modify the user object SQL query lines to accept my table name variable something like this:
Code:
$query = sprintf ('INSERT INTO $_POST['some_name']%USER (
and add to the register.php form new User code like:
Code:
$user->$_POST['some_name'];
this to get my table name variable working? Code examples most appreciated.
Jaguarcat.
Reply With Quote
  #4 (permalink)  
Old April 26th, 2012, 06:57 AM
Authorized User
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well it all depends on how much you've changed...

In theory, if just the prefix to the tables were changed, then you won't need to change anything else, but if you've changed the names of fields, or the names to the tables, that would need to be reflected in any code that requires access to those tables.

For example:
PHP Code:
// Initialize a User object.
    
public function __construct()
    {
        
$this->uid null;
        
$this->fields = array('username' => '''password' => '''email_address' => '''is_active' => false'permission' => 0);
    } 
I use slightly different naming conventions than the author of the book, so I had to change those in the user class.

Also:
PHP Code:
public static function getById($user_id)
    {
        
$user = new User();
        
$query sprintf('SELECT username, password, email_address, is_active, permission FROM %suser WHERE user_id = %d'DB_TBL_PREFIX$user_id);
        
$result mysql_query($query$GLOBALS['DB']);
        if (
mysql_num_rows($result))
        {
            
$row mysql_fetch_assoc($result);
            
$user->username $row['username'];
            
$user->password $row['password'];
            
$user->email_address $row['email_address'];
            
$user->is_active $row['is_active'];
            
$user->permission $row['permission'];
            
$user->uid $user_id;
        }
        
mysql_free_result($result);
        return 
$user;
    } 
The author uses uppercase letters for his field names, I don't... and these changes also need to be reflected in the user class.

Hope that helps to steer you in the right direction.
Reply With Quote
  #5 (permalink)  
Old May 14th, 2012, 11:34 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes: thanks Master Yoda for the example how to add a field to the User Class but I still need to add a variable to all the MYSQL query lines which brings me back to my original post question. I think I can do this if I modify the query lines But this is the block.

The query code is written with expressions
Code:
%sUSER
and
Code:
%d
I think? When I try to remove the expressions from the query lines in the USER object all actions of the User object stop. How do I remove the expressions from the query lines in the User object with modification so I can use a variable or other code within this routine?
Any examples most welcome.
Reply With Quote
Reply


Thread Tools
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
Chapter 11 Sample database Connection Closed sanmarie BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 15 May 30th, 2009 04:50 AM
Database Connection to Access Database reachsevar ASP.NET 2.0 Basics 1 November 28th, 2007 07:56 AM
database connection sandi JSP Basics 3 May 2nd, 2005 07:41 AM



All times are GMT -4. The time now is 01:29 PM.


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