Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases 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
  #1 (permalink)  
Old March 1st, 2007, 04:50 PM
Registered User
 
Join Date: Mar 2007
Location: Bernardsville, NJ, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rretzko
Default Connecting to mySQL with $this->

Hi all - I've been creating procedural code on a WAMP platform for three years. I'm just beginning to learn OOP via PHP5. Here's the problem:
I can connect to mySQL database with the following code:
$connect=mysql_connect('localhost','rick','1 23456');
$hDB=mysql_select_db('profphp5',$connect);
This works each time, every time.

When I try to OOP code this (via Programmer-to-Programmer Professional PHP5) as:
public function __construct($widgetID) {
$this->connect=mysql_connect('localhost','rick','123456' );
$this->hDB=mysql_select_db('profphp5',$this->connect);
if(! is_resource($this->$hDB)) {
     throw new Exception('Unable to connect to the database.');
}
}
I throw an Exception each time every time.

Can anyone help me solve this problem? All suggestions are appreciated!

Thanks - Rick

Rick
  #2 (permalink)  
Old March 16th, 2007, 12:03 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: South San Francisco, CA, USA.
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

Rick,
Are you using MySQL 5.0?
If you are, you need to change mysql_connect() to mysqli_connect().
How this helps,
John



Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to MYSQL from C / C++ ? oloeriubogdan Linux 1 December 15th, 2006 10:50 AM
Connecting To MySQL from PHP AlisP2P MySQL 1 January 4th, 2006 02:27 AM
Connecting to MySQL Server sleepyd BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 August 4th, 2005 09:13 AM
Connecting to mySQL WIx ASP.NET 1.0 and 1.1 Basics 3 October 17th, 2004 04:13 PM
connecting mysql with vb ks_anoop MySQL 3 February 5th, 2004 02:43 PM





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