S
S
script882012-02-22 09:59:33
PHP
script88, 2012-02-22 09:59:33

Working with an array?

Guys, there is a php class for msyql

&lt;?php<br/>
class MumbuDB {<br/>
 /**<br/>
 * Ссылка соединения<br/>
 */<br/>
 public $db_link;<br/>
<br/>
/**<br/>
 * Режим отладки<br/>
 */<br/>
 public $debugging = true;<br/>
<br/>
/**<br/>
 * Запросы<br/>
 */<br/>
 public $list_queries = array();<br/>
<br/>
/**<br/>
 * Подключение к MySQL<br/>
 */<br/>
 public function connect($DB_HOST,$DB_USER,$DB_NAME,$DB_PASSWORD){<br/>
<br/>
$this-&gt;db_link = mysql_connect($DB_HOST,$DB_USER,$DB_PASSWORD) or $this-&gt;error(&quot;Не возможно подключиться к MySQL серверу&quot;);<br/>
 mysql_select_db($DB_NAME) or $this-&gt;error('Не возможно выбрать базу данных &quot;'.$DB_NAME.'&quot;');<br/>
 mysql_query(&quot;SET NAMES UTF8&quot;);<br/>
<br/>
}<br/>
<br/>
/**<br/>
 * Аналог mysql_num_rows<br/>
 */<br/>
 public function mumbu_sql($sql){<br/>
 # Засекаем время выполнения запроса<br/>
 $start_time = microtime(true);<br/>
<br/>
# Выполняем запрос<br/>
 $result = mysql_query($sql, $this-&gt;db_link) or $this-&gt;error($sql . PHP_EOL . mysql_error($this-&gt;db_link));<br/>
<br/>
# Получаем время по окончанию запроса<br/>
 $end_time = microtime(true);<br/>
<br/>
# Высчитываем время на запрос<br/>
 $query_time = $end_time - $start_time;<br/>
<br/>
$this-&gt;list_queries[] = array(<br/>
 'query' =&gt; $query,<br/>
 'time' =&gt; $query_time<br/>
 );<br/>
<br/>
return $result;<br/>
<br/>
}<br/>
<br/>
/**<br/>
 * Аналог mysql_num_rows<br/>
 */<br/>
 public function mumbu_num_rows($sql){<br/>
<br/>
return mysql_num_rows($this-&gt;mumbu_sql($sql));<br/>
<br/>
}<br/>
<br/>
/**<br/>
 * Аналог mysql_result<br/>
 */<br/>
 public function mumbu_one($sql){<br/>
<br/>
return mysql_result($this-&gt;mumbu_sql($sql),0);<br/>
<br/>
}<br/>
<br/>
/**<br/>
 * Аналог mysql_fetch_assoc<br/>
 */<br/>
 public function mumbu_fetch($sql){<br/>
<br/>
return mysql_fetch_assoc($this-&gt;mumbu_sql($sql));<br/>
<br/>
}<br/>
<br/>
/**<br/>
 * Последний вставленный id<br/>
 */<br/>
 public function insert_id() {<br/>
 return mysql_insert_id($this-&gt;db_link);<br/>
 }<br/>
<br/>
/**<br/>
 * Закрытие соединения<br/>
 */<br/>
 public function close(){<br/>
 if($this-&gt;db_link) mysql_close($this-&gt;db_link);<br/>
 $this-&gt;db_link = NULL;<br/>
 exit;<br/>
 }<br/>
<br/>
/**<br/>
 * Вывод ошибки и завершение работы<br/>
 */<br/>
 protected function error($error){<br/>
 if($this-&gt;debugging) print &quot;<pre>&quot;. $error .&quot;</pre>&quot;;<br/>
 exit;<br/>
 }<br/>
<br/>
}<br/>
?&gt;<br/>

I then make a request:
$DB = new MumbuDB();<br/>
$DB-&gt;connect($dbhost, $dbuser, $dbname, $dbpassword);<br/>
$sql = ('SELECT * FROM `Candidate`');<br/>
$ls = $DB-&gt;mumbu_fetch($sql);<br/>
print_r($ls);

result:
Array ( [id_candidate] =&gt; 1 [fio] =&gt; Сурыев [sex] =&gt; М [age] =&gt; 23 [visa] =&gt; МО [contacts] =&gt; 8988888888 [email] =&gt; [email protected] [post] =&gt; President [income] =&gt; 10000000 [note] =&gt; ddcdcdcd )

I can not figure out how to remove an element from this array, tell me plz

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
skvot, 2012-02-22
@script88

while ($ls = $DB->mumbu_fetch($sql)) {
echo $ls['fio'];
}

S
Sergey, 2012-02-22
Protko @Fesor

echo $ls['fio'];

It's obvious to me...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question