Mysql_fetch_assoc Nasıl çözmek için () sorunlar [yinelenen]

3 Cevap php

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

When i use the code below, im getting this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

Verileri dönerken, herkes bunu düzeltebilirim? Teşekkürler!

<?php
$mysql_server_name="localhost"; 
$mysql_username=""; 
$mysql_password=""; 
$mysql_database=""; 

$conn=mysql_connect($mysql_server_name, $mysql_username,
                    $mysql_password);
?>

<?php 
$result = mysql_query("SELECT * FROM users"); 
$arrays = array(); 
while ($row = mysql_fetch_assoc($result)) { 
    foreach ($row as $key => $val) { 
        if (!array_contains_key($key)) { 
            $arrays[$key] = array(); 
        } 
        $arrays[$key][] = $val; 
    } 
} 
?> 
<script type="text/javascript"> 
<?php 
foreach ($arrays as $key => $val) { 
    print 'var ' . $key . ' = ' . json_encode($val) . ";\r\n"; 
} 
?> 
</script> 

3 Cevap

this is not mysql_fetch_assoc problem but query problem
make it

$sql="SELECT * FROM users";
$result = mysql_query($sql) or trigger_error(mysql_error().$sql); 

ve hatayı görmek

Kullanarak MySQL hata mesajlarınızı kontrol mysql_error:

<?php
$result = mysql_query('SELECT * FROM users');
$error = mysql_error();
if ($error != '')
    die($error);
?>

Genellikle Mysql bu gibi bağlantı yapın:

$con = mysql_connect("host","user","passwd");
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}