2

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.

briast
  • 286
  • 4
  • 19

1 Answers1

2

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

if ($sentencia->execute())
{

}
Mihkel Viilveer
  • 432
  • 2
  • 10
  • Another problem I have now is I have changed "$mysqli->prepare" to get parameters: $sentencia = $mysqli->prepare("select pass from users Where name ='?'"); After this, I do "if (!$sentencia->bind_param("s", $usuf)) echo "Error bind: ".$sentencia->error;" Then I get apache error "PHP Fatal error: Call to a member function bind_param() on a non-object". Why? – briast Apr 26 '13 at 11:20
  • Seems like your prepare statment fails and $sentencia is FALSE not an object. I checked the php.net and looks like you have not needed single quotes in prepare statement. – Mihkel Viilveer Apr 26 '13 at 11:41