HeresJohny

- John Skjönsberg

49 notes

I hate whitespaces more than anything right now. PHP, MySQL

They just wasted hours of my life of debugging :( But I have learned many things, this is a small memo for php-noobs like myself.

1. Pass the query to $mysqli->query() as a variable like:
$query = “insert into `db`.`table`(id,date,blah)values(”,”,”)”;
(so you can echo the query) 

2. Do the query in a if-else-statement!
if($mysqli->query($query)){ $message = “Debuggmessage: MySQL-Insert Worked<br />”; }
else{ $message = “Debuggmessage: “.$mysqli->error.”<br />”;}

3. And from now on, at least I am going to echo the query during the whole development process!
Just to see with my own eyes how it looks to the server.
echo $query.”<br />”; 

Filed under PHP MySQL Linux Apache scripting web development

  1. heresjohny posted this