ltwCalendar
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsProjectsltwCalendar

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 April 8th, 2005, 04:44 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
mysqli support

I tried to install and run ltwCalendar on PHP5 with mySQL version 4.1.7 and it doesn't work. With newer versions of mySQL, you need to use the mysqli functions in php rather than mysql. I have an updated version of ltw_classes.php available at:

http://www.bryangraham.com/ltw_classes.zip

the PHP code just for the class ltwDb is as follows:
php Code:
Original - php Code
  1.  
  2. /////////////////////////////////////////////////////////////////////////////
  3.  
  4. // class: ltwDb - common DB interface
  5.  
  6. //
  7.  
  8. // Currently, only MySql (type = 1) is supported.
  9.  
  10. // Adding other DB's should be a matter of adding cases to the
  11.  
  12. // "switch" statement for each function.
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15.  
  16. class ltwDb{
  17.  
  18. var $db_type       = '';
  19.  
  20. var $db_server   = '';
  21.  
  22. var $db_name       = '';
  23.  
  24. var $db_user       = '';
  25.  
  26. var $db_pass       = '';
  27.  
  28. var $db_persistent  = '';
  29.  
  30. var $dbh       = '';
  31.  
  32.  
  33.  
  34. // constructor 
  35.  
  36. function ltwDb(){
  37.  
  38.     global $ltw_config;
  39.  
  40.  
  41.  
  42.     $this->db_type   = $ltw_config['db_type'];
  43.  
  44.     $this->db_server    = $ltw_config['db_server'];
  45.  
  46.     $this->db_name   = $ltw_config['db_name'];
  47.  
  48.     $this->db_user   = $ltw_config['db_user'];
  49.  
  50.     $this->db_pass   = $ltw_config['db_pass'];
  51.  
  52.     $this->db_persistent    = $ltw_config['db_persistent'];
  53.  
  54.     $this->db_connect();
  55.  
  56. }// end constructor
  57.  
  58.  
  59.  
  60.  
  61.  
  62. function db_connect(){
  63.  
  64.     switch($this->db_type){
  65.  
  66.     case 1: //mysql
  67.  
  68.         if ( $this->db_persistent ){
  69.  
  70.             $this->dbh = @mysql_pconnect($this->db_server, $this->db_user, $this->db_pass);
  71.  
  72.         }else{
  73.  
  74.             $this->dbh = @mysql_connect($this->db_server, $this->db_user, $this->db_pass);
  75.  
  76.         }
  77.  
  78.         if ( !$this->dbh ){
  79.  
  80.             echo "Error: Connection to MySQL server ".$this->db_server." failed.<BR>n";
  81.  
  82.             return;
  83.  
  84.         }
  85.  
  86.         if ( !@mysql_select_db($this->db_name, $this->dbh) ){
  87.  
  88.             echo "
  89.             Error: Connection to MySQL database ".$this->db_server." failed.<BR>
  90.             ------ Code:".@mysql_errno($this->dbh).",<BR>
  91.             ------ Message:".@mysql_error($this->dbh)."<BR>
  92.             ";
  93.  
  94.             die ("Error: Fatal db Error.<br>n");
  95.  
  96.         }//end mySQL
  97.  
  98.          break;
  99.  
  100.     }//end switch
  101.  
  102. }// end function.db_connect()
  103.  
  104.  
  105.  
  106. function db_query($query = ''){
  107.  
  108.     switch( $this->db_type ){
  109.  
  110.     case 1: //mySql
  111.  
  112.         $result = mysql_query($query, $this->dbh);
  113.  
  114.         if ( !$result ){
  115.  
  116.             echo "
  117.             Error: A problem was encountered while executing this query.<br>
  118.               $query<BR><HR>$query<br>
  119.             ";
  120.  
  121.               die ("Error: Fatal db Error.<br>n");
  122.  
  123.             }
  124.  
  125.         break;
  126.  
  127.     }// end switch 
  128.  
  129.     return $result;
  130.  
  131. }// end function.db_query()
  132.  
  133.  
  134.  
  135. function db_numrows($result){
  136.  
  137.     switch( $this->db_type ){
  138.  
  139.     case 1: //mySQL
  140.  
  141.         return mysql_num_rows($result);
  142.  
  143.         break;
  144.  
  145.     }// end switch
  146.  
  147. }// end function.db_numrows()
  148.  
  149.  
  150.  
  151.    
  152.  
  153. function db_fetch_array(&$result){
  154.  
  155.     switch( $this->db_type ){
  156.  
  157.     case 1: //mySQL
  158.  
  159.         return mysql_fetch_array($result);
  160.  
  161.         break;
  162.  
  163.     }//end switch
  164.  
  165. }//end function.db_fetch_array()
  166.  
  167.    
  168.  
  169. }//end class ltwDb
  170.  



Reply With Quote
  #2  
Old April 8th, 2005, 04: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
RE: mysqli support

I noticed I'm a complete idiot and I posted the code from the unmodified version of ltw_classes. Here is the updated code - it makes use of the db_type variable from the config file, set it to two to use mysqli instead of mysql.

php Code:
Original - php Code
  1.  
  2.  
  3. /////////////////////////////////////////////////////////////////////////////
  4.  
  5. // class: ltwDb - common DB interface
  6.  
  7. //
  8.  
  9. // Currently, only MySql (type = 1) is supported.
  10.  
  11. // Adding other DB's should be a matter of adding cases to the
  12.  
  13. // "switch" statement for each function.
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16.  
  17. class ltwDb{
  18.  
  19. var $db_type       = '';
  20.  
  21. var $db_server   = '';
  22.  
  23. var $db_name       = '';
  24.  
  25. var $db_user       = '';
  26.  
  27. var $db_pass       = '';
  28.  
  29. var $db_persistent  = '';
  30.  
  31. var $dbh       = '';
  32.  
  33.  
  34.  
  35. // constructor 
  36.  
  37. function ltwDb(){
  38.  
  39.     global $ltw_config;
  40.  
  41.  
  42.  
  43.     $this->db_type   = $ltw_config['db_type'];
  44.  
  45.     $this->db_server    = $ltw_config['db_server'];
  46.  
  47.     $this->db_name   = $ltw_config['db_name'];
  48.  
  49.     $this->db_user   = $ltw_config['db_user'];
  50.  
  51.     $this->db_pass   = $ltw_config['db_pass'];
  52.  
  53.     $this->db_persistent    = $ltw_config['db_persistent'];
  54.  
  55.     $this->db_connect();
  56.  
  57. }// end constructor
  58.  
  59.  
  60.  
  61.  
  62.  
  63. function db_connect(){
  64.  
  65.     switch($this->db_type){
  66.  
  67.     case 1: //mysql
  68.  
  69.         if ( $this->db_persistent ){
  70.  
  71.             $this->dbh = @mysql_pconnect($this->db_server, $this->db_user, $this->db_pass);
  72.  
  73.         }else{
  74.  
  75.             $this->dbh = @mysql_connect($this->db_server, $this->db_user, $this->db_pass);
  76.  
  77.         }
  78.  
  79.         if ( !$this->dbh ){
  80.  
  81.             echo "Error: Connection to MySQL server ".$this->db_server." failed.<BR>n";
  82.  
  83.             return;
  84.  
  85.         }
  86.  
  87.         if ( !@mysql_select_db($this->db_name, $this->dbh) ){
  88.  
  89.             echo "
  90.             Error: Connection to MySQL database ".$this->db_server." failed.<BR>
  91.             ------ Code:".@mysql_errno($this->dbh).",<BR>
  92.             ------ Message:".@mysql_error($this->dbh)."<BR>
  93.             ";
  94.  
  95.             die ("Error: Fatal db Error.<br>n");
  96.  
  97.         }//end mySQL
  98.  
  99.          break;
  100.  
  101.     case 2: //mySQLi
  102.  
  103.         $this->dbh = @mysqli_connect($this->db_server, $this->db_user, $this->db_pass);
  104.  
  105.         if ( !$this->dbh ){
  106.  
  107.             echo "Error: Connection to MySQL server ".$this->db_server." failed.<BR>n";
  108.  
  109.             return;
  110.  
  111.         }
  112.  
  113.         if ( !@mysqli_select_db($this->dbh, $this->db_name) ){
  114.  
  115.             echo "
  116.             Error: Connection to MySQL database ".$this->db_server." failed.<BR>
  117.             ------ Code:".@mysqli_errno($this->dbh).",<BR>
  118.             ------ Message:".@mysqli_error($this->dbh)."<BR>
  119.             ";
  120.  
  121.             die ("Error: Fatal db Error.<br>n");
  122.  
  123.         }//end mySQL
  124.  
  125.          break;
  126.  
  127.     }//end switch
  128.  
  129. }// end function.db_connect()
  130.  
  131.  
  132.  
  133. function db_query($query = ''){
  134.  
  135.     switch( $this->db_type ){
  136.  
  137.     case 1: //mySql
  138.  
  139.         $result = mysql_query($query, $this->dbh);
  140.  
  141.         if ( !$result ){
  142.  
  143.             echo "
  144.             Error: A problem was encountered while executing this query.<br>
  145.               $query<BR><HR>$query<br>
  146.             ";
  147.  
  148.               die ("Error: Fatal db Error.<br>n");
  149.  
  150.             }
  151.  
  152.         break;
  153.  
  154.     case 2: //mySQLi
  155.  
  156.         $result = mysqli_query($this->dbh, $query);
  157.  
  158.         if ( !$result ){
  159.  
  160.             echo "
  161.             Error: A problem was encountered while executing this query.<br>
  162.               $query<BR><HR>$query<br>
  163.             ";
  164.  
  165.               die ("Error: Fatal db Error.<br>n");
  166.  
  167.             }
  168.  
  169.         break;
  170.  
  171.     }// end switch 
  172.  
  173.     return $result;
  174.  
  175. }// end function.db_query()
  176.  
  177.  
  178.  
  179. function db_numrows($result){
  180.  
  181.     switch( $this->db_type ){
  182.  
  183.     case 1: //mySQL
  184.  
  185.         return mysql_num_rows($result);
  186.  
  187.         break;
  188.  
  189.     case 2: //mySQLi
  190.  
  191.         return mysqli_num_rows($result);
  192.  
  193.         break;
  194.  
  195.     }// end switch
  196.  
  197. }// end function.db_numrows()
  198.  
  199.  
  200.  
  201.    
  202.  
  203. function db_fetch_array(&$result){
  204.  
  205.     switch( $this->db_type ){
  206.  
  207.     case 1: //mySQL
  208.  
  209.         return mysql_fetch_array($result);
  210.  
  211.         break;
  212.  
  213.     case 2: //mySQLi
  214.  
  215.         return mysqli_fetch_array($result);
  216.  
  217.         break;
  218.  
  219.     }//end switch
  220.  
  221. }//end function.db_fetch_array()
  222.  
  223.    
  224.  
  225. }//end class ltwDb
  226.  

Reply With Quote
Reply

Viewing: Codewalkers ForumsProjectsltwCalendar > mysqli support


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 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek