briast
briast

Reputation: 317

mysqli->execute get error but no error is output

I have the next php code:

<?php
      mysqli_report(MYSQLI_REPORT_ALL);
      $mysqli = new mysqli("localhost","mybd","mypass");
      if ($mysqli->connect_errno) { echo "Error connect<br/>"; }
      else {
            $mysqli->select_db("database1");

            if ($result = $mysqli->query("SELECT DATABASE()")) {
                $row = $result->fetch_row();
                printf("Default database is %s.\n", $row[0]);  // shows correct database selected
                $result->close();
            }

            $sentencia = $mysqli->prepare("select pass from users Where name ='ronald'");

            echo "Prepare error:".$mysqli->error."<br/>";

            if (!$sentencia) echo "<br/>sentencia is null<br/>";

            if ($sentencia->execute)
            {
                 $sentencia->bind_result($cpass);
                 $sentencia->fetch();
                 echo "Passwd:".$cpass."<br/>";    
                 $con="checkpass"; 
                 if (($con!=$cpass) && (md5($con)!=$cpass))
                 {
                      echo "OK<br/>";
                 }
                 else echo "NO OK<br/>";
            }
            else echo "<br/>Error execute: ".$mysqli->error;
     }
     mysqli_report(MYSQLI_REPORT_OFF);
 ?>

Problems are: - $mysqli->error shows nothing. No error. Always empty string. - $sentencia->execute always return null, and then always echo "Error execute:", but no information about error.

Database selected shows ok. It select the right database. This is an example. Really the name is passed with "$sentencia->bind_param("s",$user);" but with this, I get apache error of "no object". I don't know why it happens. The SQL is checked and is Ok. Thanks.

Upvotes: 2

Views: 3446

Answers (1)

Mihkel Viilveer
Mihkel Viilveer

Reputation: 432

Shouldn't execute be a function nor property? http://php.net/manual/en/mysqli-stmt.execute.php

if ($sentencia->execute())
{

}

Upvotes: 2

Related Questions