answersLogoWhite

0

You can do that using the mysql_connect() function. For example:

<?php

$host='localhost'; //Your Host Name Here

$username='root'; //MySQL Username

$pass='';//MySQL Password

$dbname='codenair'; //your Database Name

//Connecting Database

mysql_connect($host,$username,$pass)or die('Failed to Connect');

//Selecting Database

mysql_select_db($dbname)or die('Database Not Found');

echo 'Connected';

?>

User Avatar

Wiki User

7y ago

What else can I help you with?

Related Questions

How do you create a database using PHP?

The following are the fundamental procedures for creating a MySQL database with PHP: As demonstrated in this article, connect to the MySQL server from your PHP script. If the connection is successful, construct a database using SQL and save it in a string variable. Carry out the query. To learn more about data science please visit- Learnbay.co


How to you connect in mysql database?

Use the following code to connect to your mysql database from the php file. variables are hostname, db_username, db_password - see the code below for the exact connection example. &lt;?php mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); echo "Connected to MySQL&lt;br /&gt;"; ?&gt;


How do you run a MySQL query from PHP file?

Here is a simple script that you can do to run a MySQL query after you have set a database up. &lt;?php // Database Settings $db['hostname'] = "localhost"; $db['username'] = "&lt;db username&gt;"; $db['password'] = "&lt;db password&gt;"; $db['database'] = "&lt;db name&gt;"; // Connect to MySQL $connect = mysql_connect($db['hostname'], $db['username'], $db['password']); // Select Database mysql_select_db($db['database'], $connect); // Do MySQL Query mysql_query("INSERT INTO table_name SET field_name = '1234567890'"); // Close MySQL mysql_close($connect); ?&gt; Obviously you will need to use your own MySQL settings and database details, but this gives you a general overview of how you can do it.


Why to use use MYSQL with PHP and not anyother database?

You can connect any DB via PHP if you have database specific database extensions defined. LAMPP stack refer to 'Linux Apache Mysql PHP Perl'. Hence this stack is famous for php development as it include all the needed components for web development. Mysql is preferred mostly because it's extension is added by default in XAMPP or WAMPP stack.


What database does the WAmmp server refer to when it's used with PHP?

WAMP is an abbreviation of "Windows, Apache, MySQL, and PHP", so it uses MySQL database server.


What is offered by MySQL Connect?

Connection to MySQL Using PHP Script To open a database connection, PHP provides the mysqli construct or the mysqli connect() function. On success, this method returns a MySQL link identification; on failure, it returns FALSE. To learn more about data science please visit- Learnbay.co


What has the author Brad Bulger written?

Brad Bulger has written: 'MySQL/PHP database applications' -- subject(s): 004.6/82 (Computer program language), MySQL (Electronic resource), PHP (Computer program language), Web databases


Which database is good mysql or PHP?

PHP is a programming language, but MySQL is a database management system. They are two entirely different objects, and as a result, they are utilised for two quite different purposes. To learn more about data science please visit- Learnbay.co


What database does the WAMP server refer to when it?

WAMP stands for Windows Apache Mysql PHP. Mysql is the default database in WAMP


What are the advantages and disadvantages of PHP with mysql?

Ultimately PHP is a programming language and MySQL is a database language. Using PHP with MySQL is a nice combination with built-in support and the simplicity of it all. However, there aren't a lot of disadvantages of using PHP with a database, it just allows for better data organization and whatnot. There are definitely advantages and disadvantages to using a database other than MySQL (such as MongoDB or PostgreSQL).


How do you handle database in php?

Please refer link. The presentation gives complete understanding of how to deal with database (Mysql) with php.


What might be the causes of errors in PHP?

The main causes of errors in PHP can be the problems occurring from the MYSQL database (if there) or errors from Apache handler. These errors can be prevented by hosting the MYSQL database on a trusted and good server.