Error in mysql query in php

1

I have a query in DB mysql and it works fine, then I'm going to do the second query and it gives me the following error:

  

Warning: mysql_fetch_object (): supplied argument is not a valid MySQL result resource in C: \ xampp \ htdocs

Follow the PHP code below:

<php>
$open = new OpenDB();
$open->conectarNovamente($_SESSION['usuario'], $_SESSION['senha']);    

$hoje = date('Y-m-d');

$sql = "call proc_rel_controle_diario(NOW(),0,0)";  // ADD 1 dia 
$r = mysql_query($sql);
$obj = mysql_fetch_object($r);
$dia1 = $obj->total_geral;

$sql = "call proc_rel_controle_diario(NOW() + INTERVAL 1 DAY,0,0)";  // ADD 1 dia 
$r = mysql_query($sql);
$obj = mysql_fetch_object($r);
$dia2 = $obj->total_geral;
    
asked by anonymous 03.07.2014 / 13:36

2 answers

2

Yes, use MySQL and if you can also use object-oriented, your code would look like this.

$con = new mysqli(@$_SESSION['servidor'], $_SESSION['usuario'], $_SESSION['senha'], "local");

$hoje = date('Y-m-d');

$sql = "call proc_rel_controle_diario(NOW(),0,0);";  // ADD 1 dia 
$r = $con->query($sql);
$obj = $r->fetch_array();
$dia1 = $obj->total_geral;
echo $dia1;

$sql = "call proc_rel_controle_diario(NOW() + INTERVAL 1 DAY,0,0);";  // ADD 1 dia 
$r = $con->query($sql);
$obj = $r->fetch_array();
$dia2 = $obj->total_geral;
echo $dia2;

More information about MySQLi

    
03.07.2014 / 14:21
0

I solved the problem, I need to open another connection for the other procedure to work, I just do not know why.

Thanks for the tip, I'm going to use mysqli_ * because I did not even know about the discontinuation of mysql _ *.

the code stayed like this

$open = new OpenDB();
$con = mysqli_connect(@$_SESSION['servidor'],$_SESSION['usuario'],$_SESSION['senha'],"local");

$hoje = date('Y-m-d');

$sql = "call proc_rel_controle_diario(NOW(),0,0);";  // ADD 1 dia 
$r = mysqli_query($con,$sql);
$obj = mysqli_fetch_object($r);
$dia1 = $obj->total_geral;
echo $dia1;

$con = mysqli_connect(@$_SESSION['servidor'],$_SESSION['usuario'],$_SESSION['senha'],"local");
$sql = "call proc_rel_controle_diario(NOW() + INTERVAL 1 DAY,0,0);";  // ADD 1 dia 
$r = mysqli_query($con,$sql);
$obj = mysqli_fetch_object($r);
$dia2 = $obj->total_geral;
echo $dia2;
    
03.07.2014 / 14:01