Новости
Документация
Download
Webboard
Поиск
FAQ/ЧаВо
Обратная связь




MySQL.RU - Webboard



Вернуться
Вывод с классом (Coffin) 24/05/2004 - 12:38:45
      Re: Вывод с классом (haron) 24/05/2004 - 13:06:15
      Re: Вывод с классом (haron) 24/05/2004 - 13:07:16
      Re: Вывод с классом (Coffin) 24/05/2004 - 13:17:11
      Re: Вывод с классом (haron) 24/05/2004 - 13:23:18
      Re: Вывод с классом (Coffin) 24/05/2004 - 13:41:22
      Re: Вывод с классом (Coffin) 24/05/2004 - 13:58:23
      Re: Вывод с классом (haron) 24/05/2004 - 14:23:43
      Re: Вывод с классом (Coffin) 24/05/2004 - 14:28:21
      Re: Вывод с классом (Coffin) 24/05/2004 - 14:40:52
      Re: Вывод с классом (haron) 24/05/2004 - 14:57:43
      Re: Вывод с классом (haron) 24/05/2004 - 14:58:55
      Re: Вывод с классом (Coffin) 24/05/2004 - 15:02:14
      Re: Вывод с классом (haron) 24/05/2004 - 15:10:13
      Re: Вывод с классом (Coffin) 24/05/2004 - 15:24:57
      Re: Вывод с классом (Coffin) 24/05/2004 - 19:45:29
      Re: Вывод с классом (haron) 25/05/2004 - 10:57:15
      Re: Вывод с классом (Coffin) 25/05/2004 - 11:52:11
      Re: Вывод с классом (haron) 25/05/2004 - 12:51:24
      Re: Вывод с классом (Coffin) 25/05/2004 - 13:08:12
      Re: Вывод с классом (haron) 25/05/2004 - 14:22:04



From: Coffin - 24/05/2004 - 12:38:45
Subject:Вывод с классом
-----------------
Привет :) опять я!
Имеется все тотже класс :)
---------------------------------------------------------------
class db_driver {

var $obj = array ( "sql_database" => "" ,
"sql_user" => "root" ,
"sql_pass" => "" ,
"sql_host" => "localhost",
"sql_port" => "" ,
"persistent" => "0" ,
"sql_tbl_prefix" => "" ,
"cached_queries" => array(),
);

var $query_id = "";
var $connection_id = "";
var $query_count = 0;
var $record_row = array();
var $return_die = 0;
var $error = "";
var $failed = 0;

/**************************************************************************************
* Соединение с сервером MySQL *
**************************************************************************************/

function connect() {

if ($this->obj['persistent']) {
$this->connection_id = mysql_pconnect( $this->obj['sql_host'] ,
$this->obj['sql_user'] ,
$this->obj['sql_pass']
);
}
else {
$this->connection_id = mysql_connect( $this->obj['sql_host'] ,
$this->obj['sql_user'] ,
$this->obj['sql_pass']
);
}

if ( !mysql_select_db($this->obj['sql_database'], $this->connection_id) ) {
echo ("ОШИБКА: Невозможно найти базу ".$this->obj['sql_database']);
}
}



/**************************************************************************************
* Запросы к базе с использованием query *
**************************************************************************************/

function query($the_query, $bypass=0) {

$this->query_id = mysql_query($the_query, $this->connection_id);

if (! $this->query_id ) {
$this->fatal_error("mySQL query error: $the_query");
}

$this->query_count++;

$this->obj['cached_queries'][] = $the_query;

return $this->query_id;
}


// Использование функции fetch_row
function fetch_row($query_id = "") {

if ($query_id == "")
{
$query_id = $this->query_id;
}

$this->record_row = mysql_fetch_array($query_id, MYSQL_ASSOC);

return $this->record_row;

}


// Использование функции get_affected_rows
function get_affected_rows() {
return mysql_affected_rows($this->connection_id);
}


// Использование функции get_num_rows
function get_num_rows() {
return mysql_num_rows($this->query_id);
}


// Использование функции get_insert_id
function get_insert_id() {
return mysql_insert_id($this->connection_id);
}


// Использование функции get_query_cnt
function get_query_cnt() {
return $this->query_count;
}


// Освобождение памяти MySQL
function free_result($query_id="") {

if ($query_id == "") {
$query_id = $this->query_id;
}

@mysql_free_result($query_id);
}


// Закрытие соединения с MySQL
function close_db() {
return mysql_close($this->connection_id);
}


// Возвращает массив таблиц
function get_table_names() {

$result = mysql_list_tables($this->obj['sql_database']);
$num_tables = @mysql_numrows($result);
for ($i = 0; $i < $num_tables; $i++)
{
$tables[] = mysql_tablename($result, $i);
}

mysql_free_result($result);

return $tables;
}


// Возвращает массив полей
function get_result_fields($query_id="") {

if ($query_id == "")
{
$query_id = $this->query_id;
}

while ($field = mysql_fetch_field($query_id))
{
$Fields[] = $field;
}

//mysql_free_result($query_id);

return $Fields;
}


//Сообщение об ошибке
function fatal_error($the_error) {
global $INFO;

if ($this->return_die == 1)
{
$this->error = mysql_error();
$this->error_no = mysql_errno();
$this->failed = 1;
return;
}

$the_error .= "\n\nmySQL error: ".mysql_error()."\n";
$the_error .= "mySQL error code: ".$this->error_no."\n";
$the_error .= "Date: ".date("l dS of F Y h:i:s A");

$out = "<html><head><title>Invision Power Board Database Error</title>
<style>P,BODY{ font-family:arial,sans-serif; font-size:11px; }</style></head><body>
 <br><br><blockquote><b>There appears to be an error with the {$INFO['board_name']} database.</b><br>
You can try to refresh the page by clicking <a href=\"javascript:window.location=window.location;\">here</a>, if this
does not fix the error, you can contact the board administrator by clicking <a href='mailto:{$INFO['email_in']}?subject=SQL+Error'>here</a>
<br><br><b>Error Returned</b><br>
<form name='mysql'><textarea rows=\"15\" cols=\"60\">".htmlspecialchars($the_error)."</textarea></form><br>We apologise for any inconvenience</blockquote></body></html>";


echo($out);
die("");
}

/**************************************************************************************
* Форматирование строки при использовании INSERT *
**************************************************************************************/

function compile_db_insert_string($data) {

$field_names = "";
$field_values = "";

foreach ($data as $k => $v)
{
$v = preg_replace( "/'/", "\\'", $v );
//$v = preg_replace( "/#/", "\\#", $v );
$field_names .= "$k,";
$field_values .= "'$v',";
}

$field_names = preg_replace( "/,$/" , "" , $field_names );
$field_values = preg_replace( "/,$/" , "" , $field_values );

return array( 'FIELD_NAMES' => $field_names,
'FIELD_VALUES' => $field_values,
);
}

/**************************************************************************************
* Форматирование строки при использовании UPDATE *
**************************************************************************************/

function compile_db_update_string($data) {

$return_string = "";

foreach ($data as $k => $v)
{
$v = preg_replace( "/'/", "\\'", $v );
$return_string .= $k . "='".$v."',";
}

$return_string = preg_replace( "/,$/" , "" , $return_string );

return $return_string;
}

/*========================================================================*/
// Test to see if a field exists by forcing and trapping an error.
// It ain't pretty, but it do the job don't it, eh?
// Posh my ass.
// Return 1 for exists, 0 for not exists and jello for the naked guy
// Fun fact: The number of times I spelt 'field' as 'feild'in this part: 104
/*========================================================================*/

function field_exists($field, $table) {

$this->return_die = 1;
$this->error = "";

$this->query("SELECT COUNT($field) as count FROM $table");

$return = 1;

if ( $this->failed )
{
$return = 0;
}

$this->error = "";
$this->return_die = 0;
$this->error_no = 0;
$this->failed = 0;

return $return;
}

} // Конец класса db_driver

---------------------------------------------------------------

Тепрь суть вопроса !
Какой запрос нужно построить что б просмотреть все строки , одну за другой?
мне ничего лучьше в голову не пришло чем
-------------------------------------------
---Узнать количество записей в Табличке----
-------------------------------------------
$sql="Select count(id) as count from maint";
$DB->query($sql);
$row=$DB->fetch_row();
$total=$row['count'];
---------------------------------------------
потом сделать цикл от 1 до количества записей
---------------------------------------------
for($i=1;$i<=$total;$i++){
$sql="SELECT * FROM maint WHERE id=$i";
$DB->query($sql);
$row = $DB->fetch_row();
}
---------------------------------------------
работать то он работал , но пока я не начал писать удаление :) Удалялось с конца тоже хороно , НО! когда из серидины, то соответсвенно скажем id=3 удалили,осталися id{1,2,4,5,6}
то он уже не может показать нефига :( все из-за
$sql="SELECT * FROM maint WHERE id=$i";
так вот вопрос как правильно построить запрос ?
нужно я так понимаю с while! но тока что проверять в нем непойму никак :(
ПОМОГИТЕ :)
----------------------------------------------------------------
Можно прям в аську:146861130 :)
----------------------------------------------------------------
Заранее спасиб :)


[Это сообщение - спам!]

Последние сообщения из форума

Уважаемые посетители форума MySQL.RU!
Убедительная просьба, прежде чем задавать свой вопрос в этом форуме, обратите внимание на разделы:
- ответы на наиболее часто задаваемые вопросы - FAQ
- раздел документация
- раздел поиск по сообщениям форума и документации
Также, старайтесь наиболее подробно указывать свою ситуацию (версию операционной системы, версию MySQL, версию программного обеспечения, по которому возникает вопрос, текст возникающих ошибок, и др.)
Помните, чем конкретнее Вы опишете ситуацию, тем больше шансов получить реальную помощь.
 Имя:
 E-mail:
 Тема:
 Текст:
Код подтверждения отправки: Code
15100



РЕКЛАМА НА САЙТЕ
  Создание сайтов | |