0

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

what is the correct way to connect to MySQL database without the mysql_fetch_assoc() error?

Getting [Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource] with mysql_connect('localhost', 'name', 'pass'); mysql_select_db('dbname');

getting mysql_fetch_assoc() error without mysql_select_db any suggest?

CODE are:

var somethings= ;
Community
  • 1
  • 1
sky
  • 83
  • 7

8 Answers8

2

Typo? Your question has msyql_select_db instead of mysql_select_db - note the swap of the s and y in mysql.

Tim
  • 59,527
  • 19
  • 156
  • 165
1

Try:

$result= mysql_query('SELECT DISTINCT username FROM users'); 
$somethings= array(); 
while ($row= mysql_fetch_assoc($result)) { 
    $somethings[]= $row['something']; 
}

Basically changing $results to $result.

Foobar
  • 26
  • 1
  • yep, but after im getting blank page, i checked source and this is showing. Warning: json_encode() expects exactly 1 parameter, 2 given in line 17. any idea? thanks – sky Apr 19 '10 at 15:46
  • If you look at line 17, you will see you have 2 parameters to the json_encode function. There should only be 1, the data you wish to encode. – Foobar Apr 19 '10 at 15:50
0
$connect = mysql_connect('host', 'user', 'pass);
           mysql_select_db('database', $connect);

That's how you connect to a database.

You also spelled mysql wrong.

Getting Fatal error: Call to undefined function msyql_select_db() with mysql_connect('localhost', 'name', 'pass'); <<msyql>>_select_db('dbname');

Arrows around the error.

Andrew
  • 12,172
  • 16
  • 46
  • 61
0

you spelled your function incorrectly mysql not msyql

DrLazer
  • 2,805
  • 3
  • 41
  • 52
0

I do not understand your question, but maybe this will help.

$session = mysql_connect('host','username','password');

mysql_select_db('database', $session);

$resultset = mysql_query('SELECT * FROM TABLE', $session);

$result = mysql_fetch_assoc($resultset);

Good luck...

Ian P
  • 12,840
  • 6
  • 48
  • 70
0

May want to change localhost to '127.0.0.1' as well...I've had issues with that before.

Zachary Wright
  • 23,480
  • 10
  • 42
  • 56
0
<?php
  DEFINE ('DB_USER', '');     //specify the DB username like root.
  DEFINE ('DB_PASSWORD', ''); //specify the DB password.
  DEFINE ('DB_HOST', '');     //specify the DB hostname(localhost of IP address).
  DEFINE ('DB_NAME', '');    //specify the DB Name on which your doing operations.

  $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' .mysqli_connect_error() );

  $query="Specify your operation in a query format";

  @mysqli_query($dbc,$query);
  @mysqli_close($dbc);
?>
gmaliar
  • 5,294
  • 1
  • 28
  • 36
  • I wouldn't recommend suppressing any errors that may arise when trying to connect to the database. – Ian P Apr 19 '10 at 16:55
0
<?php
$result= mysql_query('SELECT DISTINCT username FROM users');  

while ($row= mysql_fetch_assoc($results)) {  
    $somethings[] .= $row['something'];  
}  
?>

Try this

Shoeb Mirza
  • 912
  • 1
  • 11
  • 30