PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I connect to mySQL from PHP?


The first thing you will need to do when using PHP and mySQL is to connect to the mySQL database from PHP.

Luckily there are a couple of functions in PHP that make it easy. Once you get it working you can just copy and paste at the top of each script that requires the database or use a template or include file of some sort to include the details.

<?php
$db 
mysql_connect("HOST""USERNAME""PASSWORD");
mysql_select_db("DATABASE_NAME",$db);
?>


And that's all there is to it - use your username, host, password and database name and this will establish the connection.

The most common problem is that you get the password wrong so double check it's right if you get errors.



ASK A QUESTION

More mysql PHP Questions

I am extracting data from a MySQL Database of which one of the data stored is seperated by a comma. For example, step1,go here,step 2,go there,step 3,go back etc etc. I want to know how to split the data at the comma and format it in html. Using the split

How do I find the ID of a new row added to a table?

How do I access the current time with mysql?

First of all I'm new to php n' mySql . So I just can't figure out what's the wrong in my code. I'm using WAMP and I've created a db named "Try" and in that there is a table named "test". this is my php code and it dosen't give me a

How do I include a conditional in my mysql query?



Custom Search