fatal error in mysql_select_db () [duplicate]

0

I am new to PHP and I am currently studying PDO , I made a simple structure and have an error that I can not identify. I've seen several examples of people using the same framework and it works.

<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "test";

$conexao = mysqli_connect($host, $user, $pass);
$db = mysql_select_db($conexao, $dbname);

$nome = "exemplo";

$consulta = mysql_query("SELECT * FROM usuarios_teste WHERE nome = $nome  ");
?>

The errors I get are:

  

Fatal error: Uncaught Error: Call to undefined function mysql_select_db ()

     

Error: Call to undefined function mysql_select_db ()

    
asked by anonymous 09.10.2018 / 15:34

1 answer

2

The mysql_select_db() function has been removed since version 7.0.0, as posted on your own documentation :

  

Warning This extension was deprecated in PHP 5.5.0, and it was removed   in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be   used. See also MySQL: choosing an API guide and related FAQ for more   information. Alternatives to this function include:

     

mysqli_select_db () PDO :: __ construct () (part of dsn)

If you are using a newer version, you will come across this problem. One solution is to use your substitute mysqli_select_db (note the "i"):

$con = mysqli_connect("localhost", "my_user", "my_password");

mysqli_select_db ( $con, $dbname );

More details: link

    
09.10.2018 / 15:44