If you need to connect php with mysql, we can use many ways.I connect php with mysql this way.I think it is very easy way. can use 5 steps.
1. Create a connection to the database
This is the first step.open a new page your text editor.type your text editor below codes.
* $connection —-> connection is a variable name.(you can use any name)
* mysql_connect —> This is a function.this help the create a connection.
* localhost —-> localhost is our host name.php is server side programing language
* root —–> login user root(MySql user name)
* ” ” —–> This is MySql password.I don’t use password when install mysql.if
you use password when install mysql, insert your password this
* die ——> Help the return the error(! $connection means not connected)
* mysql_error() —> This is also function.
2. Select the related database
* mysql_select_db —-> This is a function
* example ———–> My database name(any name can use)
We need to connect database via PHP. Firstly, create database(example).
3. Building the query
* $results ------> This is a variable name.
* SELECT * FROM ——-> This is mysql statement.it means all values select from
related table.my table name is subjects.if you like change ,you
can table name.
4. Get returned data
you build the table.you select the table in previous step.then you can get results field vise.
5. Close the connection
Finally you can close your connection.Then finish your work. enjoy..!







1 comments:
Post a Comment