SELECT PHP mysqli query won't execute
$dc=fopen("numeu.txt","rb");
$row1=fgets($dc,120);
$row2=fgets($dc,120);
$row3=fgets($dc,120);
fclose($dc);
$servername="localhost";
$username="root";
$password='';
$database="Stildev";
$conn = new mysqli($servername, $username, $password, $database);
$sql="SELECT poza1,poza2,poza3,poza4,poza5,poza6 FROM postari WHERE utilizator='".$row2."' AND subiect='".$row1."' AND id2='".$row3."'";
$resultat=$conn->query($sql);
echo $resultat->num_rows;
This piece of code returns 0 lines
There are no errors and the sql query works fine in the MySQL console.
Also I found that when discussing the WHERE clause the code works. How do you explain this?
+3
source to share
1 answer
Has the password been fixed?
Try adding
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
Also, according to https://php.net/manual/ro/mysqli.query.php this might help:
if ($result = $mysqli->query($sql)) {
echo $result->num_rows;
/* close result set */
$result->close();
}
If you are using multiple return queries, close the previous results with ->close();
+2
source to share