0

I am trying to get data from MySQL database but in the php file I get this error:

Fatal error: Call to undefined function: json_encode() in /homez.100/pizzapar/www/clic/marwa/test/base.php on line 13

Here is my php file:

<?php     
echo"welcom <br>"; 
$conn =  mysql_connect('xxx.xxx.xxx.xxx','xxx','xxx');

if ($conn) {

    mysql_select_db('zak', $conn);


    $sql=mysql_query("select * from zak_user");
  while($row=mysql_fetch_assoc($sql))
  $output[]=$row;
  print(json_encode($output));
  mysql_close();

    }
else 
{
echo"erreur connexion";
}

Can some one help?

3 Answers 3

2

According to the manual, json_encode() is available in PHP >= 5.2.0 only. You are probably running an older version.

Sign up to request clarification or add additional context in comments.

2 Comments

@manita no problem. If at all possible, upgrading to PHP 5.2 would be the best way to go
i did thanks and it works but in the emulator it show me an error JSONObject must begin with '{' or my result in the php is an array [{..},... {..}] any help about that?
1

See here: http://www.boutell.com/scripts/jsonwrapper.html

This is a replacement for JSON in earlier PHP versions.

Usage:

require 'jsonwrapper.php';

At the top of your code and you're ready to go. Of course, jsonwrapper.php must be in the same folder. If not, adjust the require command.

json_encode example

Just to give you a sense of the possibilities:

$data = array(
array('name' => 'Jane', 'age' => 35),
array('name' => 'Steve', 'age' => 37)
);
<script>
var data = <?php echo json_encode($data) ?>;
</script>

And this is the direct download: http://www.boutell.com/scripts/jsonwrapper.tar.gz

Comments

0

json_encode used to be not part of PHP, you might have to compile an extension to enable this function.

It's been awhile that json_encode is shipped with PHP(since 5.2), I advise you to upgrade.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.