Answer the question
In order to leave comments, you need to log in
Working with an array?
Guys, there is a php class for msyql
<?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->db_link = mysql_connect($DB_HOST,$DB_USER,$DB_PASSWORD) or $this->error("Не возможно подключиться к MySQL серверу");<br/>
mysql_select_db($DB_NAME) or $this->error('Не возможно выбрать базу данных "'.$DB_NAME.'"');<br/>
mysql_query("SET NAMES UTF8");<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->db_link) or $this->error($sql . PHP_EOL . mysql_error($this->db_link));<br/>
<br/>
# Получаем время по окончанию запроса<br/>
$end_time = microtime(true);<br/>
<br/>
# Высчитываем время на запрос<br/>
$query_time = $end_time - $start_time;<br/>
<br/>
$this->list_queries[] = array(<br/>
'query' => $query,<br/>
'time' => $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->mumbu_sql($sql));<br/>
<br/>
}<br/>
<br/>
/**<br/>
* Аналог mysql_result<br/>
*/<br/>
public function mumbu_one($sql){<br/>
<br/>
return mysql_result($this->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->mumbu_sql($sql));<br/>
<br/>
}<br/>
<br/>
/**<br/>
* Последний вставленный id<br/>
*/<br/>
public function insert_id() {<br/>
return mysql_insert_id($this->db_link);<br/>
}<br/>
<br/>
/**<br/>
* Закрытие соединения<br/>
*/<br/>
public function close(){<br/>
if($this->db_link) mysql_close($this->db_link);<br/>
$this->db_link = NULL;<br/>
exit;<br/>
}<br/>
<br/>
/**<br/>
* Вывод ошибки и завершение работы<br/>
*/<br/>
protected function error($error){<br/>
if($this->debugging) print "<pre>". $error ."</pre>";<br/>
exit;<br/>
}<br/>
<br/>
}<br/>
?><br/>
$DB = new MumbuDB();<br/>
$DB->connect($dbhost, $dbuser, $dbname, $dbpassword);<br/>
$sql = ('SELECT * FROM `Candidate`');<br/>
$ls = $DB->mumbu_fetch($sql);<br/>
print_r($ls);
Array ( [id_candidate] => 1 [fio] => Сурыев [sex] => М [age] => 23 [visa] => МО [contacts] => 8988888888 [email] => [email protected] [post] => President [income] => 10000000 [note] => ddcdcdcd )
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question