Connection to localhost MySQL from the Internet.
Posted: Sat Oct 01, 2005 9:55 am
feyd | Please use
Sorry if any of this is unclear, I hope you can help,
Simon
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I am going through the Create Your Own Database Driven Website book by Sitepoint and have a few questions you may be able to help me with.
For any that have the book I am working from page 77 at the moment:
The problem I am having is when I upload the code to my webspace, the database table I am trying to access is on my computers mysql (localhost i believe?) it isn't connecting to the mysql database, and I believe it is because I need the ip of my computer - where the database is stored - so that it can be accessed via a browser.
I need to find out what I need to enter here - $dbcnx = @mysql_connect ('[b]111.111.1.1[/b]', 'root', '(password for mysql'); - is it the ip address of my mac? And for the password, if I use the password for my mysql databse, will this be viewable by users who 'view source' on my web page?
I have gone to [b]system preferences/sharing/personal: web sharing[/b], as I was told this is the ip for my computer, and have these addresses:
View this computer’s website at http://111.111.1.1/ or your personal website at http://111.111.1.1/~SiBailey/
I have substituted the actual numbers for 1's as I am unsure whether I need to keep these numbers secure, but could you tell me if these are the characters I need to substitute 'localhost' for to access the mysql database on my computer, and if so how i would enter them, with the http:// or just the numbers.
The code I have so far is....Code: Select all
<?php
// Connect to the databse server
$dbcnx = @mysql_connect('111.111.1.1', 'root', '(password for mysql');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the jokes database
if (!@mysql_select_db('ijdb')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}
?>
<p>Here are all the jokes in out database:</p>
<blockquote></blockquote>
<?php
// Request the text of all the jokes
$result = @mysql_query('SELECT joketext FROM joke');
if (!@result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}
?>Simon
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]