MySQLI JSON problems.

Hello, I’m trying to output a JSON format of the selected records in my table. However, so far my only output is:

[php]string(3) “the” string(81) “SELECT ID, NewsStory, Summary1, Summary2 FROM Articles WHERE Tags = ?”[/php]

I am unsure where i have gone wrong and would be very appreciative of any help.

[php] <?php
//Open a new connection to the MySQL server
$mysqli = new mysqli(‘localhost’,‘createyo_james’,‘password’,‘createyo_TestDatabase’);

                    //Output any connection error
                    if ($mysqli->connect_error) {
                        die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
                    }
                    $myArray = array();
                    $Tags = $_GET["Tags"];

                    var_dump($_GET["Tags"]);

                    $query = "SELECT `ID`, `NewsStory`, `Summary1`, `Summary2` FROM `Articles` WHERE `Tags` = ?";

                    $statement = $mysqli->prepare($query);
                    var_dump($query);
                    //bind parameters for markers, where (s = string, i = integer, d = double,  b = blob)
                    $statement->bind_param('s', $Tags);

                    if($statement->execute()){
                                                                   
                                   
                     $statement -> execute();
                     $result = $statement -> get_result();

                     while($row = $result -> fetch_assoc()) {
                             $output[]= $row;    
                      }

                      print(json_encode($output));
                       
                       $result->close();
                      $mysqli->close();
                             }else{
                                die('Error : ('. $mysqli->errno .') '. $mysqli->error);
                            }
                            $statement->close();

            ?>[/php]

Thanks, James.

Not totally sure but I don’t think you can have spaces before or after the -> on these lines
[php]
$result = $statement -> get_result();

                      while($row = $result -> fetch_assoc()) {

[/php]

Ok i have changed the parts suggested but has not changed the overall outcome.

[php] $statement->execute();
$result = $statement->get_result();

		    while($row = $result->fetch_assoc()) {
		        $output[]= $row;    
		    }[/php]

Thanks, James.

EDIT: I turned error reporting on and the outcome was: Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/createyo/public_html/retreiveCustomArticle.php on line 26

Not sure what to change this line to however.

Thanks, James.

Here is a brief thing about that I found http://stackoverflow.com/questions/13659856/fatal-error-call-to-undefined-method-mysqli-stmtget-result
Why not just use fetch instead?

Sponsor our Newsletter | Privacy Policy | Terms of Service