[Cs-content-commits] SF.net SVN: cs-content:[390] trunk/1.0/db_types/cs_phpDB__mysql.class.php
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-06-09 18:40:03
|
Revision: 390 http://cs-content.svn.sourceforge.net/cs-content/?rev=390&view=rev Author: crazedsanity Date: 2009-06-09 18:39:50 +0000 (Tue, 09 Jun 2009) Log Message: ----------- Various fixes to work with MySQL databases. /db_types/cs_phpDB__mysql.class.php: * connect(): -- give the actual error if the connection fails. -- if no connection error is present, give a generic one so at least the developer knows *something* happened. * farray(): -- increment internal row to 1 if it's at zero. * farray_fieldnames(): -- initialize the temporary variables $tArr and $newArr. -- only add to $newArr if there's an array to be had -- throw an exception if the data from farray() isn't an array. Modified Paths: -------------- trunk/1.0/db_types/cs_phpDB__mysql.class.php Modified: trunk/1.0/db_types/cs_phpDB__mysql.class.php =================================================================== --- trunk/1.0/db_types/cs_phpDB__mysql.class.php 2009-06-08 19:12:26 UTC (rev 389) +++ trunk/1.0/db_types/cs_phpDB__mysql.class.php 2009-06-09 18:39:50 UTC (rev 390) @@ -156,9 +156,14 @@ //start output buffer for displaying error. ob_start(); - $connID = mysql_connect($this->host, $this->user, $this->pass, $forceNewConnection); - mysql_select_db($this->dbname); - $connectError = ob_get_contents(); + $connID = mysql_connect($this->host, $this->user, $this->password, $forceNewConnection); + if(!$connID) { + $connectError = mysql_error(); + } + else { + mysql_select_db($this->dbname); + $connectError = ob_get_contents(); + } ob_end_clean(); if(is_resource($connID)) { @@ -168,6 +173,9 @@ $retval = $this->connectionID; } else { + if(is_bool($connID) && !strlen($connectError)) { + $connectError = "generic connection failure"; + } throw new exception(__METHOD__ .": FATAL ERROR: ". $connectError); } } @@ -422,7 +430,9 @@ $retval = NULL; } else { - //TODO: implement MySQL version.. + if($this->row == 0) { + $this->row = 1; + } $retval = mysql_fetch_array($this->result,$this->row); } @@ -478,16 +488,23 @@ ob_start(); $x = 0; + $newArr = array(); + $tArr = array(); do { $temp = $this->farray(); - foreach($temp as $key=>$value) { - //remove the numbered indexes. - if(is_string($key)) { - $tArr[$key] = $value; + if(is_array($temp) && count($temp)) { + foreach($temp as $key=>$value) { + //remove the numbered indexes. + if(is_string($key)) { + $tArr[$key] = $value; + } } + $newArr[$x] = $tArr; + $x++; } - $newArr[$x] = $tArr; - $x++; + else { + throw new exception(__METHOD__ .": no data retrieved from farray()..."); + } } while($this->next_row()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |