开发者

What is corret way to connect to MySQL? [duplicate]

This question already has answers here: Closed 10 years ago.

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 argu开发者_开发知识库ment 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= ;


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


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.


$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.


you spelled your function incorrectly mysql not msyql


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...


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


<?php
$result= mysql_query('SELECT DISTINCT username FROM users');  

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

Try this


<?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);
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜