Lost Password?


  #1 (permalink)  
Old 09-22-2006, 07:02 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Tutorial: PHP to MySQL

Creating a connection between PHP and MySQL is fairly simple. PHP provides all of the functions you need to connect and extract data.

Before we begin have a database setup in MySQL and know the username, password and name of the database.

Create a table and add some default values into it. Remember the name of this table.

1) To connect to MySQL you really only need a few variables. To start, open notepad and add these lines:

PHP Code:
<?php
// mysql config
$mysql_username "yourname";
$mysql_password "password";
$mysql_database "db";
$mysql_server "localhost";
These are the values that we will use to connect to MySQL from PHP. Replace all of these values with your MySQL values. $mysql_server = "localhost" can generally be as is.

2) Now we will connect to MySQL using the variables above:

PHP Code:
$link mysql_connect($mysql_server$mysql_username$mysql_password);
mysql_select_db($mysql_database$link); 
As simple as that you have a connection to MySQL.

3) Lets pull some data out of our DB. You should have the table name as stated above and I named mine tbl_tutorial so replace this with your table name. We now need to build a query

PHP Code:
$query "SELECT * FROM tbl_tutorial"
4) Execute the query

PHP Code:
$results mysql_query($query$link); 
This will actually make the query on the MySQL database. Once this has been done all we need to do is fetch the results and manipulate them.

5) Display our results
PHP Code:
// Fetch results
while ($row mysql_fetch_row($results)) {

   
// Data will be displayed in an array $row[0]  
   
print "$row[0]<br>";


The $row array will contain all of the fields in your table starting with 0 and ending with the number of rows - 1.

6) Close our connection

PHP Code:
// Close our connection
mysql_close($link);

?> 
Thats it. I've attached the PHP file from this tutorial if you need to reference it.
Attached Files To view attachments in this forum your post count must be 1 or greater. You currently have 0 posts.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-30-2006, 03:55 AM
xtraze xtraze is offline
Programming God
 
Join Date: Dec 2006
Location: Sri lanka
Posts: 921
Rep Power: 0
xtraze is on a distinguished road
Send a message via MSN to xtraze Send a message via Skype™ to xtraze
Default

Really nice, I think I can extract data from my database of my Forum and display and If I knew a bit more, I think I can integrate the forum myself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-26-2007, 06:10 PM
lucky-girl's Avatar   
lucky-girl lucky-girl is offline
Newbie
 
Join Date: Dec 2007
Age: 23
Posts: 27
Rep Power: 4
lucky-girl is on a distinguished road
Default

that's what i'm looking for

u explained the tutorial in simple way

thanks Jordan
__________________
begginer programmer needs the help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-01-2008, 08:47 PM
altoyes altoyes is offline
Newbie
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0
altoyes is on a distinguished road
Default Re: Tutorial: PHP to MySQL

this code looks good, i think it is what i need. i have followed your previous tutorial, but i did not know how to use the console.... i do not know about the binary settings ...


Quote:
Originally Posted by Jordan View Post
Creating a connection between PHP and MySQL is fairly simple. PHP provides all of the functions you need to connect and extract data.

Before we begin have a database setup in MySQL and know the username, password and name of the database.

Create a table and add some default values into it. Remember the name of this table.

1) To connect to MySQL you really only need a few variables. To start, open notepad and add these lines:

PHP Code:
<?php
// mysql config
$mysql_username "yourname";
$mysql_password "password";
$mysql_database "db";
$mysql_server "localhost";
These are the values that we will use to connect to MySQL from PHP. Replace all of these values with your MySQL values. $mysql_server = "localhost" can generally be as is.

2) Now we will connect to MySQL using the variables above:

PHP Code:
$link mysql_connect($mysql_server$mysql_username$mysql_password);
mysql_select_db($mysql_database$link); 
As simple as that you have a connection to MySQL.

3) Lets pull some data out of our DB. You should have the table name as stated above and I named mine tbl_tutorial so replace this with your table name. We now need to build a query

PHP Code:
$query "SELECT * FROM tbl_tutorial"
4) Execute the query

PHP Code:
$results mysql_query($query$link); 
This will actually make the query on the MySQL database. Once this has been done all we need to do is fetch the results and manipulate them.

5) Display our results
PHP Code:
// Fetch results
while ($row mysql_fetch_row($results)) {

   
// Data will be displayed in an array $row[0]  
   
print "$row[0]<br>";


The $row array will contain all of the fields in your table starting with 0 and ending with the number of rows - 1.

6) Close our connection

PHP Code:
// Close our connection
mysql_close($link);

?> 
Thats it. I've attached the PHP file from this tutorial if you need to reference it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-01-2008, 09:00 PM
altoyes altoyes is offline
Newbie
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0
altoyes is on a distinguished road
Default Re: Tutorial: PHP to MySQL

hi jordon

it fetches the data ok
but instead of displaying an image,
it displays a number.
is this right?
have i worked the script correctly?

alto
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-22-2008, 10:15 AM
blackplastic blackplastic is offline
Newbie
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0
blackplastic is on a distinguished road
Default Re: Tutorial: PHP to MySQL

Very helpful.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-27-2008, 04:02 AM
gracie20 gracie20 is offline
Newbie
 
Join Date: Aug 2008
Posts: 4
Rep Power: 0
gracie20 is on a distinguished road
Default Re: Tutorial: PHP to MySQL

can anyone tell me from where i can get the complete infomation about php and mysql database...

Gracie Sh
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-27-2008, 09:56 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,583
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Tutorial: PHP to MySQL

Get a book, or try W3Schools Online Web Tutorials for tutorials. MySQL :: MySQL Documentation and PHP: Hypertext Preprocessor provide the documentation.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-03-2008, 06:23 PM
Tanchi Tanchi is offline
Newbie
 
Join Date: Sep 2008
Posts: 1
Rep Power: 0
Tanchi is on a distinguished road
Default Re: Tutorial: PHP to MySQL

thanx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-05-2008, 01:12 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,583
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Tutorial: PHP to MySQL

Er, welcome.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
John's Java Tutorial Index John Java Tutorials 0 01-11-2007 04:05 PM
MySQL Resources dirkfirst Database & Database Programming 1 05-25-2006 03:31 AM


All times are GMT -5. The time now is 07:27 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads