php-mysqlHow to change database in MySQL with PHP?
To change the database in MySQL with PHP, you can use the mysqli_select_db()
function. This function takes two parameters, the first being the MySQLi connection object and the second being the name of the database you want to select.
$conn = mysqli_connect("localhost", "username", "password");
$db_selected = mysqli_select_db($conn, "database_name");
The code above will connect to the MySQL server and select the database with the name database_name
.
The parts of the code are:
$conn
: This is the MySQLi connection object.mysqli_connect()
: This is the function used to connect to the MySQL server. It takes three parameters, the first being the hostname, the second being the username and the third being the password.mysqli_select_db()
: This is the function used to select the database. It takes two parameters, the first being the MySQLi connection object and the second being the name of the database you want to select.
Helpful links
More of Php Mysql
- How to use a variable in a MySQL query using PHP?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to check the result of an insert in PHP and MySQL?
- How to get the version of MySQL using PHP?
- How to fetch data from MySQL in PHP?
- How to get a single value from query in PHP MySQL?
- How to get the first row of a result in MySQL using PHP?
- How to update to null value in MySQL using PHP?
- How to use a MySQL union in PHP?
- How to generate a UUID in MySQL using PHP?
See more codes...