You are here: Re: Just not getting it--need help with Generate Report function « All PHP « IT news, forums, messages
Re: Just not getting it--need help with Generate Report function

Posted by robert on 05/11/06 01:58

| It appears as though I'm missing some components here such as
| mdb.class.php. Is this from the PEAR???

again, mdb.class.php is a ficticious name...i don't know what modules you
have or what are required...i'm not at all a fan of pear.


| The only other thing I see that I'm not that familar with is
| db_dbArray. I can't find much when googled.

i'll post a db class you can use...it will work out of the box with mysql
(that is what you have, correct?) as long as you are using php 5...if not,
well...


| So perhaps I should start from scratch in hopes of solving this thing
| without PEAR. Though from what I'm reading, using the PEAR is suppose
| to make things "easier." I'm not sure if PEAR is installed on the
| hosting company's server; I am trying to find out.

well, what it is supposed to do and what it actually does are two different
tales altogether...and yes, it is a pain in the ass when your isp doesn't
have it installed nor wants it installed.



| If I'm not mistaken, the following portion of my script creates two
| arrays: sel_groups and sel_cols.
|
| Is this a true statement?

it appears so...though i configure mine a bit differently:

<input name="sel_groups[<?= $id ?>]" type="checkbox" />

and

<input name="sel_cols[<?= $name ?>]" type="checkbox" />




==== free-bee

useage:

<?
require_once 'db.class.php';

db::connect('localhost', 'user', 'password', 'sampleDb');

$sql = "
SELECT Foo
FROM bar
WHERE 1 = 1
";
$records = db::execute($sql);
foreach ($records as $record)
{
echo '<pre>' . $record['FOO'] . '</pre>';
}
?>

==== db.class.php

<?
class db
{
static private $_instance = null;
static private $_lastStatement = '';

private function __clone(){}

private function __construct(){}

static function connect($server, $user, $password, $catalog = null)
{
try
{
mysql_connect($server, $user, $password);
if (!is_null($catalog)){ mysql_select_db($catalog); }
} catch (exception $ex) {
print "<pre>\r\n" . $ex->getMessage() . "\r\n" .
' in file ' . $ex->getFile() . "\r\n" .
' on line ' . $ex->getLine() . "\r\n" .
'</pre>';
return false;
}
return true;
}

static function getInstance()
{
if (is_null(self::$_instance)){ self::$_instance = new db(); }
return self::$_instance;
}

static function getLastStatement(){ return self::$_lastStatement; }

static function decode($string)
{
$translation = get_html_translation_table(HTML_ENTITIES);
$translation = array_flip($translation);
$string = strtr($string, $translation);
return $string;
}

static function encode($string)
{
$translation = get_html_translation_table(HTML_ENTITIES);
$string = strtr($string, $translation);
return $string;
}

static function execute($sql, $decode = false, $returnNewId = false)
{
self::$_lastStatement = $sql;
$array = array();
$key = 0;
$records = mysql_query($sql);
$fieldCount = @mysql_num_fields($records);
$translation = get_html_translation_table(HTML_ENTITIES);
$translation = array_flip($translation);
while ($row = @mysql_fetch_array($records, MYSQL_NUM))
{
for ($i = 0; $i < $fieldCount; $i++)
{
$value = $row[$i];
if ($decode){ $value = strtr($value, $translation); }
$array[$key][strtoupper(@mysql_field_name($records, $i))] = $value;
}
$key++;
}
if ($returnNewId)
{
$array = array();
$array[0]['ID'] = mysql_insert_id();
}
@mysql_free_result($records);
return $array;
}

static function prepare($string, $encode = false)
{
if ($encode){ $string = self::encode($string); }
$string = stripslashes(str_replace("'", "''", $string));
return $string;
}
}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация