How do I query a MySQL database from a PHP script?
In todays web hosting tutorial we are going to cover :
How do I query a MySQLdatabase from a PHPscript?
Use the following outline to connect and begin querying the MySQL server from within your PHP scripts. Remember if you are a Pixel Internet customer you cannot connect to your databases remotely for security reasons; you can only connect from localhost.
1. Connect to the MySQL Server
Use the following statement to connect to the database server. Substitute the ‘username’ and ‘password’ for those that have been created in your control panel and have given adequate permissions to this database.
mysql_connect(‘localhost’,'USERNAME’,'PASSWORD’);
2. Select Your Database
Use the following statement to select the database you wish to connect to. Make sure you substitute your database name.
mysql_select_db(“DATABASENAME”);
3. Executing A Query
You are now ready to execute your queries. Most problems that arise with your scripts will be caused by incorrect permission settings or syntax errors within the code.
Account Manager at Pixel Internet, Doug has been with us from day one. With over 10 years experience working in the web design and search engine optimisation industry, Doug's input and contribution to the growth of the company has been invaluable.
Pixel Internet specialise in web hosting for the following Open Source software packages, many of which include 'one-click-installation' via your control panel!
Click on a link below for more information regarding these packages and what we can offer.
Linux Web Hosting is probably the most used server operating system in the market. Most web developers love Linux because it will support PHP and MySQL perfectly.
Windows Web Hosting is used if your choice of programming language is ASP.NET or if you need to run MSSQL databases. As a rule we normally suggest that unless you need these features it's advisable to select a Linux based hosting plan.
Free Email Hosting
Purchase or transfer a domain name to Pixel Internet and you can add our FREE Email Only plan and receive 5 email accounts.
Simply order our Free Email Only plan when placing your order.