___ ___ erkimt Error in MySQL "expects parameter 1 to be resource, boolean given in" ______ qstntxt ___
%pre%

I have this code and can not see error in it, but it gives me this error. I know there should already be a topic of this on the site but I have tried all the ways and nothing. Give me the bool error (false)

    
______ azszpr28190 ___

This error happens when %code% or %code% fails, it is usually a syntax error in the sql query and returns a %code% as explained in manual . For mysql_fetch _ * () to function properly you must pass a variable of type %code% or %code% which is the return of %code% / %code% on success.

To fix the error you can force mysql_ * mysqli _ mysqli _ to display the database error with the mysql_error () or mysqli_error ()

Version with old mysql functions _ *

%pre%

Version with mysqli_ * procedural

%pre%

Version with mysqli_ * OO

%pre%

The query will return this error because %code% is a reserved mysql word.

  

Error Code: 1064. You have an error in your SQL syntax; check the   manual that corresponds to your MySQL server version for the right   syntax to use near 'desc'

The other way is to print the query and test directly at the database:

%pre%

Related:

Why should not we use functions of type mysql_ *?

MySQL vs PDO - which is the most recommended for to use?

How to print the SQL statement being sent to the bank?

    
______ azszpr333477 ___

The problem occurs because the %code% method needs a parameter with the connection to the database.

I leave an example below. Remember to modify the data to connect to the bank.

I leave it as a hint for you to study using the PDO because it is safer and the %code% is already depreciated.

  

Example:

%pre%     
___

14
$query = "Select * from servico where ID_SERVICO = $id";
$result = mysql_query($query);
if($row = mysql_fetch_array($result)) {
    $nome = $row['NOME'];       

    if($nome == 'Marketing') {
        include ("servicos/marketing.php"); 
    }
    if($nome == 'Web-Marketing') {              
        include ('servicos/webmarketing.php');
    }
    if($nome == 'Serviços Web') {
        include ("servicos/servicosweb.php");
    }
    if($nome == 'Design Gráfico') {
        include ("servicos/designgrafico.php");
    }
}

I have this code and can not see error in it, but it gives me this error. I know there should already be a topic of this on the site but I have tried all the ways and nothing. Give me the bool error (false)

    
asked by anonymous 07.08.2014 / 19:13

2 answers

13

This error happens when mysql_query() or mysqli_query() fails, it is usually a syntax error in the sql query and returns a false as explained in manual . For mysql_fetch _ * () to function properly you must pass a variable of type resource or mysqli_resource which is the return of mysql_query() / mysqli_query() on success.

To fix the error you can force mysql_ * mysqli _ mysqli _ to display the database error with the mysql_error () or mysqli_error ()

Version with old mysql functions _ *

$sql = 'SELECT * FROM desc';
$resource = mysql_query($sql) or die(mysql_error());

Version with mysqli_ * procedural

$sql = 'SELECT * FROM desc';
$resource = mysqli_query($sql) or die(mysqli_error($conexao));

Version with mysqli_ * OO

$sql = 'SELECT * FROM desc';
$resource = $db->query($sql) or die($db->error);

The query will return this error because desc is a reserved mysql word.

  

Error Code: 1064. You have an error in your SQL syntax; check the   manual that corresponds to your MySQL server version for the right   syntax to use near 'desc'

The other way is to print the query and test directly at the database:

$sql = 'SELECT * FROM desc';
echo $sql;

Related:

Why should not we use functions of type mysql_ *?

MySQL vs PDO - which is the most recommended for to use?

How to print the SQL statement being sent to the bank?

    
07.08.2014 / 20:07
0

The problem occurs because the mysql_query method needs a parameter with the connection to the database.

I leave an example below. Remember to modify the data to connect to the bank.

I leave it as a hint for you to study using the PDO because it is safer and the mysql_* is already depreciated.

  

Example:

$query = "Select * from servico where ID_SERVICO = $id";
// variavel com a conexão do banco de dados.
$conn = mysql_connect('servidor', 'usuario', 'senha') or die ('Verifique seus dados de conexão com o banco de dados. Detalhes: ' . mysql_error());
// selecionando banco de dados
mysql_select_db('nome_do_banco', $conn);

$result = mysql_query($query, $conn);
if($row = mysql_fetch_array($result)) {
    $nome = $row['NOME'];       

    if($nome == 'Marketing') {
        include ("servicos/marketing.php"); 
    }
    if($nome == 'Web-Marketing') {              
        include ('servicos/webmarketing.php');
    }
    if($nome == 'Serviços Web') {
        include ("servicos/servicosweb.php");
    }
    if($nome == 'Design Gráfico') {
        include ("servicos/designgrafico.php");
    }
}
    
01.10.2018 / 18:25