mysql_fetch_array()

  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

hey,

i just moved to a friends' host (onehost.ws) and when i use my site there, its actually not working.
As is, the database connection isnt.
I already notice that the phpmyadmin is different, you can only choose between primary, indexed & unique, instead of all.

Anyways, when i enter the url for the index file, i get the site with its images but with the error
Code: [ Select ]
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/omegades/public_html/ts/index.php on line 203


which seems like *plum*, cause its the same code i used for connecting to the database on lycos.

the code for putting the values of the tabular news into an array ($news[]) is as following:

Code: [ Select ]
<?php
//Connects to database
$db = mysql_connect("localhost", "", "") or die ("Connection to database failed");
mysql_select_db("localhost", $db);
$news_SQL = "SELECT * FROM news ORDER BY news_datetime DESC";
$news_result = mysql_query($news_SQL);
?>
....
while($news = mysql_fetch_array($news_result)) {
posting code
}
  1. <?php
  2. //Connects to database
  3. $db = mysql_connect("localhost", "", "") or die ("Connection to database failed");
  4. mysql_select_db("localhost", $db);
  5. $news_SQL = "SELECT * FROM news ORDER BY news_datetime DESC";
  6. $news_result = mysql_query($news_SQL);
  7. ?>
  8. ....
  9. while($news = mysql_fetch_array($news_result)) {
  10. posting code
  11. }


i removed the usrname/pass

whats going on?
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

It looks like you're not selecting a valid database name...

Code: [ Select ]
mysql_select_db("", $db);

http://www.php.net/mysql_select_db wrote:
bool mysql_select_db ( string database_name [, resource link_identifier])

Returns TRUE on success or FALSE on failure.

mysql_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if mysql_connect() was called without arguments, and use it.

Every subsequent call to mysql_query() will be made on the active database.

Example 1. mysql_select_db() example

Code: [ Select ]
<?php

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password')
  or die('Not connected : ' . mysql_error());

// make foo the current db
mysql_select_db('foo', $link) or die ('Can\'t use foo : ' . mysql_error());

?>
  1. <?php
  2. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password')
  3.   or die('Not connected : ' . mysql_error());
  4. // make foo the current db
  5. mysql_select_db('foo', $link) or die ('Can\'t use foo : ' . mysql_error());
  6. ?>
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

yeah i did, it was localhost, i just removed it
anyways, the problems not there anymore. got around it.
now it has the problem with

Code: [ Select ]
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/omegades/public_html/ts/index.php on line 203
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

No, localhost is the HOSTNAME, NOT the name of the database :)
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

i had the database name there before, which created a different error..till i put up localhost there.....now it sticks with this one.
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

Okies, well, 'localhost' isn't going to work for the DATABASE name unless your actual database's name IS 'localhost' - which it probably isn't. 'localhost' would be the hostname of the MySQL server.

Make sure you are using the correct database name. If you are using the correct database name, and you're getting errors, check the username & password, if you're still getting errors, make sure the username you're using actually has access to the database you're attempting to use.
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

all checked and approved :?
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

Ok, and the MySQL request you're doing is..

Code: [ Select ]
SELECT * FROM news ORDER BY news_datetime DESC


Have you tried executing that through phpMyAdmin, or the MySQL command line client to see if there's an error coming up?
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

yes, the fields show up like theyre supposed to in phpmyadmin.

However, I noticed the datetime continues to have the standard value (0000-00-00 00:00:00)

I added something to the fields manually through phpmyadmin.

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 126 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.