mysql connect
Before you can do anything with MySQL in PHP, you must first establish a connection in the database of your web host. It is done with the MySQL connect function.
mysql localhost
On the off chance that you've been around the web a while, you'll realize that IP addresses are utilized as identifiers for PCs and web servers. In this case of an association content, we accept that the MySQL benefit is running on an indistinguishable machine from the content.
At the point when the PHP content and MySQL are on a similar machine, you can utilize localhost as the deliver you wish to interface with. localhost is an alternate route to simply have the machine associate with itself. In the event that your MySQL benefit is running at a different area you should embed the IP address or URL set up of localhost. It would be ideal if you contact your web have for more points of interest if localhost does not work.
PHP & MySQL Code:
<?php
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
Display:
Connected to MySQL
If you load the above PHP scripts on your webserver and everything works well, you should see "connected to MySQL" when viewing the .php page.
The Mysql_connect function takes three arguments. The I server, user name and password were in our example above these arguments:
Server - localhost
Username - Administrator
Password - 1 day
choosing the working database
PHP & MySQL Code:
<?php
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("test") or die(mysql_error());
echo "Connected to Database";
?>
Display:
Connected to MySQL
Connected to Database
Connected to Database
0 comments:
Post a Comment