Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional PHP6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional PHP6
This is the forum to discuss the Wrox book Professional PHP6 by Edward Lecky-Thompson, Steven Nowicki; ISBN: 9780470395097
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional PHP6 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 August 16th, 2011, 04:18 AM
Registered User
 
Join Date: Aug 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 3: class.DataManager.php for MySQL

Hi there,

First of all, I'm really enjoying your book until now. It has been very helpful.

The only problem is: I'm using MySQL and not PostgreSQL. It's not a problem with the queries, the only problem is with the _getConnection() method.

In order to connect to a PostgreSQL database, you only need to use the pg_connect() function, and then simply return it.

But when using MySQL, you need to first use the mysql_connect() function, and then mysql_select_db(). The mysql_connect() function is the one should be returned.

I thought about something like this:
PHP Code:
        private static function _getConnection()
        {
            static 
$hDB;
            
            if (isset(
$hDB))
                return 
$hDB;
            
            
$hDB mysql_connect("localhost""root""") or die(mysql_error());
            
mysql_select_db("wrox_contactmanager"$hDB) or die(mysql_error());
            
            return 
$hDB;
        } 
Is that okay?
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
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 09:57 AM
Adapting class.DataManager for MySQL mercury7 PHP Databases 0 January 16th, 2006 01:37 PM
php won't inseret in MYSQL chapter 3 mAhmed BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 March 28th, 2005 12:03 PM
Chapter 9 - Apache, PHP and Mysql Development AMP_Engineer Beginning PHP 1 September 25th, 2004 11:27 AM
Vector class php cslcs BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 March 12th, 2004 02:52 PM



All times are GMT -4. The time now is 03:21 PM.


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