Re: Thoughts on real cause of a 500 internal server error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



That does make sense, and will definitely look into reordering the code to
first check that something has been returned, but was actually under
impression that had to execute data_seek(0) before could retrieve num_rows
property, but, this does actually make more sense, but, you'll see in my
other mail that it actually came down to me mistyping the connection
password variable name...:)

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message ----- From: "Jean Rafael Tardem Delefrati" <jeandelefrati@xxxxxxxxx>
To: "'Jacob Kruger'" <jacobk@xxxxxxxxxxxxxx>
Sent: Monday, March 12, 2012 4:12 PM
Subject: RES:  Thoughts on real cause of a 500 internal server
error


Ok, your linebreaks didn't worked very well, so, I suppose that the command
that is causing trouble is "$res->data_seek(0);", right?

Anyway, I think that the problem is being generated because (maybe) there is
no result  for the object $res and you are trying to move the pointer to the
position 0, but there is no 0 position, because $res is null.
I guess (if this is the error) that you could avoid it by checking if the
result is null and if there is any result using the property num_rows(),
like this:

if($res = $mysqliObj->query($sql)){
if($res->num_rows()>0){
$res->data_seek(0);
/* The rest of your code that depends on $res here! */
}
}

You should consider validate some errors before executing some command in
the database, using mysqli->error(), mysqi->errno(),
mysqli->connect_error(), mysqli->connect_errno(), mysqli_debug(), etc.

[]'s

Jean Rafael Tardem Delefrati


-----Mensagem original-----
De: Jacob Kruger [mailto:jacobk@xxxxxxxxxxxxxx]
Enviada em: segunda-feira, 12 de março de 2012 10:50
Para: php-windows@xxxxxxxxxxxxx
Assunto:  Thoughts on real cause of a 500 internal server error

In the below bit of code, that last line causes server to bomb out with an
HTTP 500 Internal Server Error, but, for example if I comment out that line,
and get it to echo the $sql string value, that I can quite happily get it to
run via a form of query analyzer, returning a record set, etc., but really
just wondering what could be causing this issue, when similar code is
running quite happily on various other pages in same site, using same
include files for things like host name, database values, etc. etc.


Code snippet:
/* there's not much above this aside from setting the values of a couple of
string variables to possibly populated in code below to give them sort of
default values, and a check of $_SESSION variables to make sure they're set
*/

require("dbInc.php"); //this populates variables to be used for connection
$sql = sprintf("select vEmail, vName from %s where id = %s;", $tableUsers,
$_SESSION["id"]); $mysqliObj = new mysqli($dbHost, $dbUser, $dbPassword,
$dbDB); $res = $mysqliObj->query($sql); $res->data_seek(0); //this is the
line of code that causes page to bomb out completely

/* there is otherwise code below here that carries on with calling
fetch_assoc() against $res object, sets variable values, closes connection,
etc. etc. */

Will also try implementing more descriptive error management to see if can
get more info from server itself, but it currently literally just renders
the message about HTTP 500 internal server error.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux