Jump to content

[PHP][MySQL] problem with mysql_connect


latino.ad7

Recommended Posts

I have a problem when using mysql_connect and I can't properly connect to the database. I use WebServ. I had it working OK, but now after reinstall, something is wrong and I can't determine what.

 

I used PHPMyAdmin to set up a table called "objects" in database "mydb". I input one sample record.

 

When I run php code I get the following message: Resource id #3. What's wrong??

 

The variable $r (see the code below) doesn't seem to include anything.

 

Here is PHP code:

 

$hostt = 'localhost';

$userr = 'root';

$passw = '';

$baz = 'mydb';

 

$link = mysql_connect ($hostt, $userr, $passw);

$db = mysql_select_db($baz, $link);

 

$q = ("Select * from objects");

$r = mysql_query ($q, $link);

 

echo $r;

Link to comment
Share on other sites

Ah, certainly. Thank you so much. It works! :)

 

How do I process this query correctly?

 

It works ok when I add:

$row = mysql_fetch_array($r);

echo $row[0];

echo $row[1];

 

But it fails to work in a loop:

while ($row = mysql_fetch_array($r)) {

echo $row['name'];

}

 

How do I type that correctly?

 

Let's say that my table "objects" consists of 3 columns: id, name, author.

And I have 2 rows:

0, "aaa", "aaa0"

1, "bbb", "bbb0"

Link to comment
Share on other sites

Thanks. That's what I did finally:

 

$hostt = 'localhost';

$userr = 'root';

$passw = '';

$baz = 'mydb';

 

$link = mysql_connect ($hostt, $userr, $passw);

$db = mysql_select_db($baz, $link);

 

$q = ("Select id, filename, name, author, bin from objects where category = 'mycategory');

$r = mysql_query ($q, $link);

 

while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {

$arrid[$row['id']] = $row['id'];

$arrfilename[$row['id']] = $row['filename'];

$arrname[$row['id']] = $row['name'];

$arrauthor[$row['id']] = $row['author'];

$arrbin[$row['id']] = $row['bin'];

 

echo $arrname[0];

Link to comment
Share on other sites

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.