Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional PHP6
|
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 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 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?





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 10:57 AM
Adapting class.DataManager for MySQL mercury7 PHP Databases 0 January 16th, 2006 02: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 01: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 03:52 PM





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