[PHP-DB] Re: extract data from database into an array

2002-07-15 Thread Marcel Schindler


Chip Wiegand [EMAIL PROTECTED] wrote
 I have a database, all the data is numbers. I want to make a query that
 will extract the data and then make it available in an array, so the
 array is populated 'real-time'. I could just enter the number into an
 array manually, but I want to automate the job. I don't know what to
 start looking for, the 3 books I have either don't talk about this or I
 just am missing it.
 Could someone point me in the right direction?

This class makes it possible to return an array in two ways very easy.

Just try this

$db = new Ms_db;
$db-connect(true);  // open a persistant connection
$vars1 = $db-query(SELECT * FROM table);
$vars2 = $db-query(SELECT * FROM table,off);

$vars1 is now build this way
$vars1[row][column] contains the required value...

$vars2[column][row] contains the required value...


Maybe this helps:
?php
/**
mySQL - Database Class
**/

// Database Configuration Variables (local) //
  define (DB_SERVER,localhost);
  define (DB_USER,root);
  define (DB_PASS,);
  define (DB_DB,testfaq);


class Ms_db
{
/**
* Attributes of this class
**/
var $db_result   = 0; // Stores the last result_id
var $db_id   = 0; // Stores the current Database Connection ID
var $db_datasets = array(); // Stores the last read database-Set as hash
[colum-name][row_number]

/**
* Connect
* @author Marcel Schindler
* @param bool $persistant
* @return void
**/
function connect($persistant =
FALSE,$server=DB_SERVER,$user=DB_USER,$pass=DB_PASS,$database=DB_DB)
{
if (($persistant == FALSE))
{
$this-db_id = @mysql_connect($server,$user,$pass)
   or $this-db_error(Failed to connect to
Database-Server,mysql_error());
}
else
{
$this-db_id = @mysql_pconnect($server,$user,$pass)
   or $this-db_error(Persistant connection
failed,mysql_error());
}
@mysql_select_db($database) or $this-db_error(Failed to select
Database,mysql_error());
}

/**
* Query
* @param SQL-Query
* @param flip boolean
* @return array $dataset
**/
function query($sql,$flipped=on)
{
$db = $this-db_id;
$wert = array();
$count= 0;
if (!$db) $this-db_error(Keine Verbindung zur Datenbank);
$res = @mysql_query($sql) or $this-db_error(Fehlerhaftes
SQL-Statement,$sql.br.mysql_error());
while ($data = mysql_fetch_assoc($res))
{
$wert[$count] = $data;
$count  ;
}
if ($flipped == on) $wert = $this-reorder_array($wert);
$this-db_datasets=$wert;
return $wert;
}



/**
* Close - closes the connection to the Database
**/
function close()
{
mysql_close();
}

/**
* Reorder_array
* @param: $array = array();
* @return: $array;
**/
function reorder_array($arr)
{
$wert = array();
// Array ist vom Typ $wert[Zeile][Spalte], soll aber als
$wert[Spalte][Zeile]
foreach ($arr as $sub)
{
while (list ($key1,$val1) = each ($sub))
{
$wert[$key1][] = $val1;
}
}
$this-db_datasets = $wert;
return $wert;
}

/**
* db_error - displays a well-formatted HTML-Page with the error-message
* @param string errormessage
* @param string mysql-error (optional)
**/
function db_error($message,$error='')
{
echo 'htmlheadtitle'.$message.'/title/headbody
bgcolor=#ee';
echo 'table align=center width=600 height=400
bgcolor=#ff';
echo 'trtdh1Error:/h1/td/trtrtd';
highlight_string($message);
if ($error!='')
{
echo 'brbrMySQL said:'.$error;
}
echo '/td/tr/table/body/html';
die();
}

/**
* NumRows
* Checks the Number of rows affected by the last query
* @return integer $number
**/
function numrows()
{
$number = @mysql_num_rows($this-db_result);
return $number;
}
/**
* DUMP - just dumps the current array (just for informal purposes
* @param VOID
**/
function dump()
{
$x = $this-numrows();
if ($x == 0 ) $this-db_error(There was no query placed
before,);
echo 'strongQuery DUMP/strongbrtable border=1
cellspacing=0 cellpadding=0 width=100%tr';
$wert = $this-db_datasets;
$spalten = array_keys($wert);
foreach ($spalten as $values)
{
$spaltenname[] = $values;
echo th bgcolor=\#00\font
color=\#ff\$values/font/th;
}
echo /tr;
for ($t = 0; $t = $x; $t  )
{
if ($t % 2 == 0) echo tr bgcolor=\#dd\;
else echo tr bgcolor=\#ee\;
foreach($spaltenname as $values)
{
echo td vAlign=\top\.$wert[$values][$t]./td

Re: [PHP-DB] Problem whith mysql_connect()

2002-07-10 Thread Marcel Schindler


Fernando Gonzalez [EMAIL PROTECTED] wrote
 Php Was installed when installing the Red Hat 7.0 .
 Mysql Was installed later from rpm.

 Any ideas of what can I do???

write this script
?php phpinfo(); ?

save and start it through your browser.

Check the following parts:

CONFIGURE COMMAND: Is --with-mysql=/path/to/mysql standing there? (right
on top of the phpinfo)



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Re: Great tool

2002-07-10 Thread Marcel Schindler

César aracena [EMAIL PROTECTED] wrote:
 Hi all. I found in one of these DB lists a word about a tool called
 MySQL - Front so I went there, downloaded it and ran it today for the
 first time and well...
 ¡¡TWO THUMBS UP!!!
 It really seems like a great GUI app. I installed it over Win XP Pro and
 had no troubles with it so far. It's amazing how much graphical
 possibilities it has. Really recommend it for *EVERY* newbie like me and
 for all Masters who doesn't know it.

Yeah, I downloaded it, but I could not get access to my mysql-server... I
dunno why, any ideas?
Client is windows XP and Server is RH 7.2



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] template problem!!!

2002-07-08 Thread Marcel Schindler

 Hi

 Just enclose it in ?php ?

 You can do this in either templates or html pages
Yeah, but this is against the template-system. Of course, this is possible
but templates are usually for seperating the code from the design



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Problem with arrays

2002-06-14 Thread Marcel Schindler

Hi there,

Sorry for my bad english.

I want to read a table from a mySQL-database and store it in an array built
like this:

$value[column][row];

I am not sure, how this is done.



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php