Jump to content
xisto Community
Sign in to follow this  
iGuest

mysql in php

Recommended Posts

mysql with php. Continued from the php tutorial

this uses tables like Excel...

sooo you create headings for tables along the x axis.....and can have lots of rows with different values. Its called a database..but the best analogy is probably with excel.

You can use php to insert data, delete data, or edit data.... but..

1) first you need to connect.

e.g. at the top of the page you need to write something like this ADJUSTING the values for your host:

<?//set database connection variables$hostname='localhost';$uname='';$password='';$database='';//establish database connectionmysql_connect($hostname,$uname,$password);?>

you can make this a bit more complicated....to produce an error if it doesnt work, and if it does, to select the database:

//set database connection variables$hostname='localhost';$uname='username';$password='password';$database='database name';//establish database connection$connect = mysql_connect($hostname,$uname,$password);//display error if connection failsif ($connect==FALSE) {   print 'Unable to connect to database: '.mysql_error();} else {//select databasemysql_select_db($database);}/*-----------------------------------*/?>

Now.... either of those will work..or should do :)

You can use them in 1 of 2 ways...

for instance, you could save one as db.php
then write

<?include 'db.php';////make the rest of the page?>

at the top of each php file that you want to use the database in.

or you could just write it out over and over again in each page - most sites use the first idea.


then add / insert delete files...

more added later... people who want to take it further feel free to do so in a reply

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.