Lost Password?

  #1 (permalink)  
Old 09-22-2006, 06:02 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 25
Posts: 4,524
Last Blog:
PHP: Variable variable...
Rep Power: 50
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
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 your post count must be 1 or greater. Your post count is 0 momentarily.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
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, 02: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, 05:10 PM
lucky-girl lucky-girl is offline
Newbie
 
Join Date: Dec 2007
Age: 23
Posts: 26
Rep Power: 2
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, 07: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, 08: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, 09: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
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

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


All times are GMT -5. The time now is 05:59 PM.

Contest Stats

John ........ 87.50000
dargueta ........ 75.00000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads