Script work on different servers


  • QA Engineer

    There is a violin:

    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    

    <?php
    $mysqli =mysqli_connect('---', '---', '---', '---');
    if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: ".mysqli_connect_error();
    }
    $result = $mysqli->query('SELECT * FROM climat');
    $rows = array();
    $table = array();
    $table['cols'] = array(
    array('label' => 'date', 'type' => 'string'),
    array('label' => 't_in', 'type' => 'number')
    );
    foreach($result as $r) {

     $temp = array();
     $temp[] = array('v' =&gt; (string) $r['date']); 
     $temp[] = array('v' =&gt; (float) $r['t_in']); 
     $rows[] = array('c' =&gt; $temp);
    }
    

    $table['rows'] = $rows;

    $jsonTable = json_encode($table);
    echo $jsonTable;
    ?>

    On one PHP server, Version 5.6.11, mysql 5.6.27 works.
    And on another PHP server Version 5.3.21, mysql 5.5.28 is not working.
    No data.

    How can this problem be addressed?



  • @Alexei-Shiman &apos; s rights should be determined when choosing a procedural or objective style.

    The following is the condom(s) and the rest will be rewritten by yourself. http://php.net/manual/ru/mysqli.quickstart.stored-procedures.php ♪

    P.S. To make it clear what it is, the code must be in such a way:

    instead $r['date'] - Category $r->date etc.

    # Сам коннект
    $mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
    if ($mysqli->connect_error) {
        die('Ошибка подключения (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
    }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2