 |
Если вы впервые на нашем форуме - ознакомьтесь с правилами
|
|
решил создать класс для работы с базой (mysql)
класс должен возвращать:
1)список баз данных
2)список таблиц в базе
3)имена полей таблицы
4)сами строки таблицы
С 1 и 2 работает ,проблемма с 3 и 4.
Вот сам класс:
class get_base
{
public $DBname,$rows,$cols,$field_N,$res,$Query;
private $showTables,$showDBname;
public function __construct()
{
$this->Query = $Query;
$this->DBname = $DBname;
$this->rows = $rows;
$this->cols = $cols;
$this->field_N = $field_N;
$this->res = $res;
$this->showDBname = mysql_list_dbs();
$this->showTables = mysql_query("SHOW TABLES;");
mysql_select_db($this->DBname);
$this->charset = mysql_client_encoding();
}
function base_R() //список баз
{
$this->rows = mysql_num_rows($this->showDBname);
for($i=0;$i<$this->rows;$i++)
{
$this->res[] = mysql_db_name($this->showDBname, $i);
}
return $this->res;
}
function table_R() // cписок таблиц
{
$this->res = mysql_list_tables($this->DBname);
while ($row = mysql_fetch_row($this->res)) {
print "Таблица: $row[0]<br>";
}
}
function field_N() // поля таблицы и содержимое
{
$this->res = mysql_query($this->Query);
while ($row = mysql_fetch_assoc($this->res)) {
$field[] = $row;
}
return $field;
}
}
$DB = new get_base();
$DB->DBname = "base";
$DB->Query = "select * from table;";
$field=$DB->field_N();
foreach ($field as $key=>$val)
{
print($val."<br>");
}
выводит ошибку:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:wwwDbasemenu2.php on line 64
|
|
21 января 2006, 15:00
|
|
Это сообщение было просмотрено: 8566 раз(а)
|
 |