php - select from one database and update into another with matching rows -


select database values , update database same id : error getting trying property of non-object how can achieve there solution ??

   $servername = "localhost";    $username = "root";    $password = "pass";    $dbname = "db1";    $dbname2="db2";      $conn = new mysqli($servername, $username, $password, $dbname);     if ($conn->connect_error) { die("connection failed: " . $conn->connect_error);    }       $conn2 = new mysqli($servername, $username, $password, $dbname2);     if ($conn2->connect_error) { die("connection failed: " . $conn2->connect_error);    }      $sql = "select * affiliates";    $result = $conn->query($sql);     if ($result->num_rows > 0) {    //output data of each row        while($row = $result->fetch_assoc()) {             echo "from db1 id: " . $row["id"]. "publish " .$row["publishinsuppliercontants"]. "<br>";        $sql2 = "update a1_affilates_cstm set publish_in_supplier_contacts_c=".$row["publishinsuppliercontants"]." id_c=".$row["id"]."";      $result2 = $conn2->query($sql2);      $sql2 = "select * a1_affilates_cstm id_c = ". $row["id"]."";      $result2=mysqli_query($conn2,$sql2) or die mysqli_error($conn2);     $row1 = mysqli_fetch_array($result2);    ///check whether inserted ...            echo "from db2 id: " . $row1["id_c"]. " - publish: ".row1["publish_in_supplier_contacts_c"]. " <br>";         }    } else {        echo "0 results";    } 

it looks don't result object. select query ?

you need check select query state/result before make operation result object.

for example in case:

$sql = "select * affiliates"; if ( $result = $conn->query($sql) ) {   if ($result->num_rows > 0) {      ... logic ... 

from php mysqli manual:

"returns false on failure. successful select, show, describe or explain queries mysqli_query() return mysqli_result object. other successful queries mysqli_query() return true."


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -