|
Posted by Steve on 02/15/07 23:33
"edward_sanders" <edward_sanders@bellsouth.net> wrote in message
news:5m5Bh.10221$m7.1060@bignews5.bellsouth.net...
| Ok Steve,
| I tried that echo statement you gave and the
| results are not what I was expecting or can make
| sense of at all. I get everything right with the code
| except for the fact that the ID is not getting passed. I
| checked the db from the mysql cmd prompt and got
| this information, which is wierd because ID is spelled
| just like it is my code. So that wasn't the problem.
| Here are the fields which I got from
| Describe jokes; :::
| ID int(11) Not Null, Pri, auto_increment
| JokeText type: text NULL
| JokeDate type: date not null
| AID type int(11) Null
ok...this response will one of a couple.
here's a db abstraction class. the db implemented is mysql...so you just
have to include this and you're set. next post will have the core 'template'
of managing your jokes.
file name: 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 describe($table)
{
$columns = array();
$records = self::execute('DESCRIBE ' . $table);
foreach ($records as $record)
{
foreach ($record as $column => $property)
{
if ($column == 'FIELD'){ continue; }
$columns[strtoupper($record['FIELD'])][$column] = $property;
}
}
return $columns;
}
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]
|