php - Mysql insert and select query together convert to mysqli -


i have mysql query works great when try convert mysqli can not work: working sql query

<?php  require_once( 'opendb.php' );  $id = '105';     // start date     $date = '2015-11-10';     // end date     $end_date = '2015-11-15';      while (strtotime($date) <= strtotime($end_date)) {      $sql= "insert test (id,date,hours) select  id, '".$date."' date, case dayname('".$date."')     when 'sunday' sun     when 'monday' mon     when 'tuesday' tue     when 'wednesday' wed     when 'thursday' thu     when 'friday' fri     when 'saturday' sat else 0 end hours emp id = '".$id."'"; mysql_query($sql);     $date = date ("y-m-d", strtotime("+1 day", strtotime($date)));     }?> 

not sure how use mysqli prepare statement when there select , insert in same query.

mysqli not working not sure how work

  <?php      $mysqli = new mysqli('localhost', 'xx', 'xx', 'xxx');      $id = '105';         // start date         $date = '2015-11-10';         // end date         $end_date = '2015-11-15';      $stmt = $mysqli->prepare('insert `test` (`id`, `date`,`hours`) values (?, ?, ?)');             while (strtotime($date) <= strtotime($end_date)) {            $sql= "select  id,     '".$date."' date,     case dayname('".$date."')         when 'sunday' sun         when 'monday' mon         when 'tuesday' tue         when 'wednesday' wed         when 'thursday' thu         when 'friday' fri         when 'saturday' sat     else 0 end '".$hours."'     emp id = 105 ";     $mysqli->query($sql);;           $stmt->bind_param('sss', $id , $date, $hours);             $stmt->execute();         $date = date ("y-m-d", strtotime("+1 day", strtotime($date)));         }     ?> 

i understand how use prepare in insert statement not when insert , select statement together

the select statement taking each day column hours work on day table 1 eg id mon = 8 tue = 6 wed = 4 thu= 0 fri = 6 sat = 7 sun = 0 , insert them test table

it looks using select in sql date formatting. date formatting in php, instead. make mysqli insert plain vanilla insert.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -