PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old June 5th, 2006, 05:46 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
Connecting to DB w/ MDB2

I previously followed a tutorial for DB abstraction using PEARB and everything worked fine until this last weekend. I'm not quite sure what happened but most logs point to an upgrade of the MySQL server I'm using as a backend. Anyway I noticed the package "DB" was superseeded by MDB2 anyway so I tried to upgrade my code to the new format and am having problems. Please help!

Here are my installed PEAR packages -

Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.1 stable
Console_Getopt 1.2 stable
DB 1.7.6 stable
HTTP 1.2.2 stable
MDB2 2.0.3 stable
MDB2_Driver_mysql 0.2.3 beta
Mail 1.1.10 stable
Mail_Mime 1.3.1 stable
Net_SMTP 1.2.6 stable
Net_Socket 1.0.1 stable
OLE 0.5 beta
PEAR 1.4.6 stable
Spreadsheet_Excel_Writer 0.9.0 beta
XML_Parser 1.0.1 stable
XML_RPC 1.1.0 stable


I'm using Debian 3.1 (Sarge) and PHP4.


Here is my config file:

php Code:
Original - php Code
  1.  
  2. /** Database Configuration */
  3. //require the PEAR::DB classes.
  4.  
  5. // require_once 'DB.php';
  6. require_once 'MDB2.php';
  7.  
  8. $db_engine = 'mysql';           //mysql = MySQL, pgsql = PostgreSQL, mssql = Microsoft SQL Server
  9. $db_user = 'user';   //Username
  10. $db_pass = 'pass';   //Password
  11. $db_host = 'localhost';         //Host
  12. $db_name = 'db_name';   //Database name
  13.  
  14. $datasource = $db_engine.'://'.
  15.                           $db_user.':'.
  16.                           $db_pass.'@'.
  17.                           $db_host.'/'.
  18.                           $db_name;
  19.  
  20. $db_object = MDB2::connect($datasource, TRUE);
  21.  
  22. // assign database object in $db_object,
  23. // if the connection fails $db_object will contain
  24. // the error message.
  25.  
  26. // If $db_object contains an error:
  27. // error and exit.
  28.  
  29. if(PEAR::isError($db_object)) {
  30.         die($db_object->getMessage());
  31. }
  32.  
  33. $db_object->setFetchMode(DB_FETCHMODE_ASSOC);


Is this correct and how should I call it?

Duane

Reply With Quote
  #2  
Old June 21st, 2006, 05:02 AM
adn83an adn83an is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: jordan
Posts: 1 adn83an User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to adn83an
RE: Connecting to DB w/ MDB2


Quote:
I previously followed a tutorial for DB abstraction using PEARB and everything worked fine until this last weekend. I'm not quite sure what happened but most logs point to an upgrade of the MySQL server I'm using as a backend. Anyway I noticed the package "DB" was superseeded by MDB2 anyway so I tried to upgrade my code to the new format and am having problems. Please help!

Here are my installed PEAR packages -

Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.1 stable
Console_Getopt 1.2 stable
DB 1.7.6 stable
HTTP 1.2.2 stable
MDB2 2.0.3 stable
MDB2_Driver_mysql 0.2.3 beta
Mail 1.1.10 stable
Mail_Mime 1.3.1 stable
Net_SMTP 1.2.6 stable
Net_Socket 1.0.1 stable
OLE 0.5 beta
PEAR 1.4.6 stable
Spreadsheet_Excel_Writer 0.9.0 beta
XML_Parser 1.0.1 stable
XML_RPC 1.1.0 stable


I'm using Debian 3.1 (Sarge) and PHP4.


Here is my config file:

php Code:
Original - php Code
  1.  
  2. /** Database Configuration */
  3. //require the PEAR::DB classes.
  4.  
  5. // require_once 'DB.php';
  6. require_once 'MDB2.php';
  7.  
  8. $db_engine = 'mysql';           //mysql = MySQL, pgsql = PostgreSQL, mssql = Microsoft SQL Server
  9. $db_user = 'user';   //Username
  10. $db_pass = 'pass';   //Password
  11. $db_host = 'localhost';         //Host
  12. $db_name = 'db_name';   //Database name
  13.  
  14. $datasource = $db_engine.'://'.
  15.                           $db_user.':'.
  16.                           $db_pass.'@'.
  17.                           $db_host.'/'.
  18.                           $db_name;
  19.  
  20. $db_object = MDB2::connect($datasource, TRUE);
  21.  
  22. // assign database object in $db_object,
  23. // if the connection fails $db_object will contain
  24. // the error message.
  25.  
  26. // If $db_object contains an error:
  27. // error and exit.
  28.  
  29. if(PEAR::isError($db_object)) {
  30.         die($db_object->getMessage());
  31. }
  32.  
  33. $db_object->setFetchMode(DB_FETCHMODE_ASSOC);


Is this correct and how should I call it?

Duane


Reply With Quote
  #3  
Old November 26th, 2007, 12:42 AM
DeeJay DeeJay is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 1 DeeJay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 59 sec
Reputation Power: 0
This may work

I just found this, and although it's a very old thread, I thought I would still give my input (since it still shows up on Google and I just had the same problem).

I was using PostgreSQL, however- but my problem was similar in the sense that nothing seemed wrong but I still could not connect... this is what solved it for me:

I set localhost(80) as the host. I think this is to explicitly tell it to connect using port 80, which may be a restriction set in place for that particular DB user, as it appears to have been for me.

Try it if you still have, or end up again experiencing, that problem. It may work for you.


Forgive me if I am off-base in my explanation of this solution... I am still relatively new to DSN and DB abstraction layers.





Quote:
Originally Posted by Anonymous
I previously followed a tutorial for DB abstraction using PEARB and everything worked fine until this last weekend. I'm not quite sure what happened but most logs point to an upgrade of the MySQL server I'm using as a backend. Anyway I noticed the package "DB" was superseeded by MDB2 anyway so I tried to upgrade my code to the new format and am having problems. Please help!

Here are my installed PEAR packages -

Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.1 stable
Console_Getopt 1.2 stable
DB 1.7.6 stable
HTTP 1.2.2 stable
MDB2 2.0.3 stable
MDB2_Driver_mysql 0.2.3 beta
Mail 1.1.10 stable
Mail_Mime 1.3.1 stable
Net_SMTP 1.2.6 stable
Net_Socket 1.0.1 stable
OLE 0.5 beta
PEAR 1.4.6 stable
Spreadsheet_Excel_Writer 0.9.0 beta
XML_Parser 1.0.1 stable
XML_RPC 1.1.0 stable


I'm using Debian 3.1 (Sarge) and PHP4.


Here is my config file:

php Code:
Original - php Code
  1.  
  2. /** Database Configuration */
  3. //require the PEAR::DB classes.
  4.  
  5. // require_once 'DB.php';
  6. require_once 'MDB2.php';
  7.  
  8. $db_engine = 'mysql';           //mysql = MySQL, pgsql = PostgreSQL, mssql = Microsoft SQL Server
  9. $db_user = 'user';   //Username
  10. $db_pass = 'pass';   //Password
  11. $db_host = 'localhost';         //Host
  12. $db_name = 'db_name';   //Database name
  13.  
  14. $datasource = $db_engine.'://'.
  15.                           $db_user.':'.
  16.                           $db_pass.'@'.
  17.                           $db_host.'/'.
  18.                           $db_name;
  19.  
  20. $db_object = MDB2::connect($datasource, TRUE);
  21.  
  22. // assign database object in $db_object,
  23. // if the connection fails $db_object will contain
  24. // the error message.
  25.  
  26. // If $db_object contains an error:
  27. // error and exit.
  28.  
  29. if(PEAR::isError($db_object)) {
  30.         die($db_object->getMessage());
  31. }
  32.  
  33. $db_object->setFetchMode(DB_FETCHMODE_ASSOC);


Is this correct and how should I call it?

Duane

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > Connecting to DB w/ MDB2


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek