Ardinent Posted March 18, 2011 Share Posted March 18, 2011 Hey there, total n00b here... Just installed and learned the basic functions of PHP and MySQL (Only have very basic programming background.) Also managed to get an Apache server running. I'm attaching a screenshot that should explain my problem entirely but in short... I can connect to and send SQL queries to my MySQL server using my terminal. My browser reads php statements over the apache server fine and it 'seems' to connect to my MySQL server fine, but it won't select a database and doesn't seem to accept other SQL queries. If I use a non-existant server name I get an error code but when I change to a non-existant user name I don't get an error code. So I'm not sure if it actually does connect or not or why the other queries doesn't work. As I said I'm VERY new to this, so I might be making some other mistake as well. Please see attached document/screenshot. Thank you Ardinent [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/231008-mysql-connection-uncertainty/ Share on other sites More sharing options...
Pikachu2000 Posted March 18, 2011 Share Posted March 18, 2011 Try changing Ardinent.local to localhost in the php script and see if that doesn't clear it up. (moving thread to php coding help) Quote Link to comment https://forums.phpfreaks.com/topic/231008-mysql-connection-uncertainty/#findComment-1189168 Share on other sites More sharing options...
Ardinent Posted March 18, 2011 Author Share Posted March 18, 2011 Hi Pikacu2000, thank you for your reply and moving it to the appropriate section. I tried change Ardinent.local to localhost, but getting the same result. Any other ideas? Any cfg files I should paste? There's just so many, wasn't sure which ones to add. Thank you ARdinent Quote Link to comment https://forums.phpfreaks.com/topic/231008-mysql-connection-uncertainty/#findComment-1189184 Share on other sites More sharing options...
jcbones Posted March 18, 2011 Share Posted March 18, 2011 Change: $db = mysql_select_db('test',$connection) or die('Could not connect to database'); //to $db = mysql_select_db('test',$connection) or die('Could not connect to database: ' . mysql_error()); See what happens. Quote Link to comment https://forums.phpfreaks.com/topic/231008-mysql-connection-uncertainty/#findComment-1189221 Share on other sites More sharing options...
Ardinent Posted March 18, 2011 Author Share Posted March 18, 2011 Hi jcbones, That worked, I think. Lol. Now the program runs all the way through ... So I've got php functionality going over my Apache server. This string shouldn't display as the program exits at the mysql_select_db line Okay, so here we go with the real stupid question... Should the following bit display the result of the query or is another command needed to display the result of the query? $query = "SELECT * FROM pet"; $result = mysql_query($query) or die ("Couldn't execute query"); Thanks dude! Quote Link to comment https://forums.phpfreaks.com/topic/231008-mysql-connection-uncertainty/#findComment-1189239 Share on other sites More sharing options...
jcbones Posted March 18, 2011 Share Posted March 18, 2011 There are 3 different commands that will get the result list from the resource. $query = "SELECT * FROM pet"; $result = mysql_query($query) or die ("Couldn't execute query"); //This returns the resource. //get the result list #1 (not recommended.) while($row = mysql_fetch_array($result)) { //function returns a numerical and an associative array. foreach($row as $key => $value) { //you will find that you have 2 of everything. echo $key . ': ' . $value . '<br />'; } } //get result list #2. while($row = mysql_fetch_row($result)) { //function returns a numerical array. foreach($row as $key => $value) { echo $key . ': ' . $value . '<br />'; } } //get result list #3 while($row = mysql_fetch_assoc($result)) { //function returns an associative array. foreach($row as $key => $value) { echo $key . ': ' . $value . '<br />'; } } Quote Link to comment https://forums.phpfreaks.com/topic/231008-mysql-connection-uncertainty/#findComment-1189249 Share on other sites More sharing options...
Ardinent Posted March 18, 2011 Author Share Posted March 18, 2011 Thank you very much, now it's back to the books! Really appreciate it. Have a good one dude! Quote Link to comment https://forums.phpfreaks.com/topic/231008-mysql-connection-uncertainty/#findComment-1189250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.