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
  #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: 24
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!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway