sql:connection

liunx

Guest
This is probably gonna be a stupid question to you all but ive been thinkin about starting my own webpage and using mysql/php to design a member system. I knew nothing about either of the two so i did some reading and i have a question about connecting to mysql server. my question is if i have to connect to the server which is on my computer and i have dial-up internet access then doesnt the changing IP address make it impossible?? I know that this is a really stupid question and i feel stupid for asking it but i cant find the answer to it anywhere.what IP address?

you should connect as LOCALHOST on both and the username and password are the only things that change.ok so then how does the webpage connect to the database to edit the information if u dont connect from the webpage to the sql serverJust put the following in your php file before you do anything with the database.


<?
//Variables to hold MySQL USERNAME / PASWORD
$user = "USERNAME here";
$pass = "PASSWORD here";
// Variable to hold MySQL connection:
$connect = mysql_connect("localhost", $user, $pass) or die(mysql_error());
// Variable to hold DB name:
$db = "Database Name";
// Select DB:
mysql_select_db($db, $connect) or die(mysql_error());
?>


Then your queries would look similar to this:

<?
// Variable to hold table name:
$table_name = "TABLE NAME here";
//Variable to hold query:
$sql = "SELECT * FROM $table_name"; // or what ever query string you need to use
//Variable to hold query results:
$results = mysql_query($sql, $connect) or die(mysql_error());
//Then you can do what every you want with the query results using
// the variable $results. Say for example, you can put them into
// an array:


// Select each column from the DB and put them into the $row array, then give them there own variables so they
// can be called else where in the script.
while ($row = mysql_fetch_array($results))
{

$id = $row['id'];
$misc = $row['misc'];
// etc....
}
?>


I hope that helps. If not, Im sure scoutt will be able to help you. Im still kinda new to php/mysql.Originally posted by newb_needs_help
ok so then how does the webpage connect to the database to edit the information if u dont connect from the webpage to the sql server
because when php makes the connection it just knows. mysql is bundled with php so it does its job. if it didn't make a connection you would see undefinded function in the browser window.Thanx to all of you..u've all been lots of help..i just have one more question where can i find a really good php/mysql tutorial that breaks it down and explains it step by step i guess ive looked but cant find any that i can understand.. all the computer lingo confuses meUnfortunatly, I do not know of any good tutorials. I would recommend going to your local book store and / or library.

MySQL/PHP Database Applications( by Jay Greenspan and Brad Bulger ) is a very helpful book.<!-- m --><a class="postlink" href="http://www.snippetlibrary.com/tutorials.php?kid=11&catname=Databases">http://www.snippetlibrary.com/tutorials ... =Databases</a><!-- m -->
 
Top