php - Insert Data from one mysql table to another ( Notice: Array to string conversion ) -
i trying data htmlcode
table tickets
in database , trying insert in table users
here flowing code wrote , gives me error notice: array string conversion
i have little bit of idea stupidity trying insert array database should string , there easier way transfer data 1 table or correction of flowing code ?
<?php try{ $conn = new pdo("mysql:host=localhost;dbname=mydb", "dbuser", "mypass"); } catch(pdoexception $pe) { die('connection error, because: ' .$pe->getmessage()); } $sql = "select `htmlcode` `tickets`"; $stmt = $conn->query($sql); if(!$stmt) { die("execute query error, because: ". $conn->errorinfo()); } $row = $stmt->fetch(pdo::fetch_assoc); // print_r ($row); //prints array $sql = "insert users (row) values (:tickets)"; $stmt = $conn->prepare($sql); $stmt->bindparam(':tickets' , $row); $stmt->execute(); ?>
you can single query:
insert users (row) select htmlcode tickets limit 1 /* since original script doesn't loop, copies 1 row */
$conn->errorinfo()
returns array, not string, can't print directly. try:
die("execute query error, because: ". implode(' ', $conn->errorinfo()));
Comments
Post a Comment