
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we select a MySQL database by using PHP script?
As we know that PHP provides us the function named mysql_select_db to select a mysql database.
Example
To illustrate this we are selecting a database named ‘Tutorials’ with the help of PHP script in the following example −
<html> <head> <title>Selecting MySQL Database</title> </head> <body> <?php $dbhost = 'localhost:3036'; $dbuser = 'guest'; $dbpass = 'guest123'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db( 'TUTORIALS' ); mysql_close($conn); ?> </body> </html>
- Related Questions & Answers
- How can we delete a MySQL database by using PHP script?
- How can we create a new database by using PHP script?
- How can we create a MySQL table by using PHP script?
- How can we create a MySQL temporary table by using PHP script?
- How can we delete an existing MySQL table by using PHP script?
- How can we handle NULL values stored in a MySQL table by using PHP script?
- How can we insert data into an existing MySQL table by using PHP script?
- How can we write PHP script to get the list of MySQL database?
- How can we write PHP script to count the affected rows by MySQL query?
- How can we create a new database by using mysqladmin?
- How can we establish MySQL database by using MySQL binary at command prompt?
- How can we drop an existing database by using mysqladmin?
- Which PHP function is used to establish MySQL database connection using PHP script?
- Write an example to establish MySQL database connection using PHP script?
- After connecting to MySQL server how can we select a database from command prompt?
Advertisements