Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/231008-mysql-connection-uncertainty/
Share on other sites

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

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!

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 />';
}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.