Is there any way I can change data from different columns but leave it in a single variable? [closed]

0

In short .... Use multiple updates in a single variable

Type:     $ query = 'update .....; update ......... '

Is there anyway?

    
asked by anonymous 22.08.2015 / 22:23

1 answer

2

You should be using mysql_query , but only accept one query. Try using mysqli :: multi_query . An example;

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* verifica conexão */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query  = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";

/* executa a sua multi query */
if ($mysqli->multi_query($query)) {
    do {
        /* Faz print separado do resultado de cada query */
        if ($result = $mysqli->store_result()) {
            while ($row = $result->fetch_row()) {
                printf("%s\n", $row[0]);
            }
            $result->free();
        }
        /* separa cada resultado por traços */
        if ($mysqli->more_results()) {
            printf("-----------------\n");
        }
    } while ($mysqli->next_result());
}

/* fecha conexão */
$mysqli->close();
?>
    
23.08.2015 / 00:10