Problems with PHP 5.2

Asked

Viewed 85 times

0

I made a page of Admin for a website and when I climbed on the server I found out that the PHP version is 5.2 and there is no way I can update, the server always introduce me error in function mysql_fetch_array(), i wonder if you have an equivalent function for php 5.2 and if PDO could solve my problem?

That’s the code I made:

$selecao = mysql_query("SELECT * FROM nome_table WHERE nivel = 'Cliente' 
                        ORDER BY nome_contato"); 

while ($selecao_dados = mysql_fetch_array($selecao)) { 

    echo $id = base64_encode($selecao_dados['id_user']); 

} 

The mistake:

inserir a descrição da imagem aqui

  • 1

    I believe that PDO would solve, but your code we can not know, as Mutley said, but I also found a topic on this subject -> http://stackoverflow.com/questions/11004500/is-mysql-fetch-array-supported-in-php-5-2-6

  • 2

    You could provide some code for us to help, too.

  • <?php $selectao = mysql_query("SELECT * FROM name_table WHERE nivel = 'Client' ORDER BY name_contact"); while ($select_data = mysql_fetch_array($selected)) { echo $id = base64_encode($selected_data['id_user']); } ?>

  • 1

    Ask [Edit] the question and put the code there.

  • http://meutema.hol.es/img/error.PNG

  • This error means that the query failed, the value of nivel came blank.

  • On the line of mysql_query, in place of ; put this code, or die(mysql_error()); and see if another error appears.

  • Take a look which may be the same problem as yours: http://stackoverflow.com/questions/11004500/is-mysql-fetch-array-supported-in-php-5-2-6

Show 4 more comments

1 answer

1

Try modifying your code for something like:

$querySQL = 'SELECT * FROM tabela_usuario WHERE id = 1234';
$query = mysql_query($querySQL);

if (!($row = mysql_fetch_array($query, MYSQL_ASSOC)))
{
    echo 'Usuário não encontrado!';
} else {
    while ($row = mysql_fetch_array($query, MYSQL_ASSOC))
        var_dump($row);
    echo 'Usuário encontrado!';
}

I tested it here and it worked perfectly(PHP VERSION 5.6.3), needing clear adaptations, for your need... in the case of SQL;

  • this is the problem my script works well from version 5.3 but in 5.2 which is the version that this on the server it presents me several errors, I even tried to see in the PHP documentation if it had any function equivalent to mysql_fetch_array() but I did not find anything.

  • You changed your code to the one described above and tested?

  • Yes I changed, and it presented the same errors in the function mysql_fetch_array().

  • 1

    Swap your mysql_query here => mysql_query($query)or die( mysql_error() ); and let us know if an error has occurred.

  • 1

    Thanks so much for the help, I just solved the problem, it was an error in my database settings, now everything is already correct.

  • 1

    @mikaellemos033 Edit your question and ask how you solved your problem, so if something happens with the comments, the solution will not be lost.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.