The Phpmyadmin nay is a database and mysql nay connects via HTTP, mysql itself is already a proper TCP protocol.
Mysql and Phpmyadmin difference
read this:
Don’t use the old API
The functions that begins with mysql_
in the prefix are Old API, read this:
How to use the Mysqli API to connect to the Mysql database
The variable $host
should contain only the HOST of your mysql server, which has nothing to do with Apache and nothing to do with HTTP:
<?php
$host = 'localhost';
$usuario = 'root';
$senha = 'minhasenha';
$banco = 'meubanco';
$link = mysqli_connect($host, $usuario, $senha, $banco);
if (mysqli_connect_error()) {
printf('Erro de conexão: %s', mysqli_connect_error());
exit;
}
if (!mysqli_set_charset($link, 'utf8')) {
printf('Error ao usar utf8: %s', mysqli_error($link));
exit;
}
if ($result = mysqli_query($link, 'SELECT * FROM nome')) {
/* Pegando os dados */
while ($row = mysqli_fetch_assoc($result)) {
echo $row['nome'];
}
/* libera os resultados */
mysqli_free_result($result);
} else {
/*Trata o erro da query, se ocorrer*/
printf('Erro na query: %s', mysqli_error($link));
exit;
}
/* fecha a conexão */
mysqli_close($link);
Handling error in query:
Probably your query is wrong, so you commented:
With mysqli another error occurs, in the case of Mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given - Otávio Guilherme
As an example I made, have an if and an Else:
if ($result = mysqli_query($link, 'SELECT * FROM nome')) {
... SE OCORRER TUDO NORMAL ...
} else {
... SE TIVER UM ERRO NA QUERY ...
}
UTF-8
If not using UTF-8 remove this part:
if (!mysqli_set_charset($link, 'utf8')) {
printf('Error ao usar utf8: %s', mysqli_error($link));
exit;
}
put only localhost and mysql is being discontinued, use mysqli, Give some error?
– Anderson Henrique
Yes, the following errors have occurred Fatal error: Uncaught Error: Call to Undefined Function mysql_select_db() in C: wamp64 www pedemoca model conexao.php on line 7 ( ! ) Error: Call to Undefined Function mysql_select_db() in C: wamp64 www pedemoca model conexao.php on line 7
– Otávio Guilherme
Do the Following $connected = mysql_connect('localhost', usuario_bd, password_bd); and in mysql_select_db(name_bd, $connected); and have this removed in php 7 if you are using 7 it will not work you have to go to mysqli
– Anderson Henrique