Store a value in MySQL made from gmdate() in PHP -


i have code:

$vid_length = gmdate("h:i:s", $ytarr['length_seconds']);  $query = $conn->prepare("insert videos (owner_id, video_url, vid_length, thumbnail_url, title) values (:owner_id, :video_url :vid_length, :thumbnail_url, :title) "); $query->execute(array(     ':owner_id' => $_post['owner_id'],     ':video_url' => $youtube_link,     ':vid_length' => $vid_length,     ':thumbnail_url' => (string) $ytarr['thumbnail_url'],     ':title' => (string) $ytarr['title'] )); 

if remove code related vid_length, other values stored fine. vid_length in however, query doesn't work.

i tried making vid_length column time, datetime , varchar/text while casting (string) $vid_length.

any suggestions make work?

ps: $vid_length becomes of format 00:02:39 (after converting seconds) $ytarr['length_seconds'] number (ie 264s seconds)

you try sec_to_time(seconds) in query perform conversion .

also missed coma between :video_url , :vid_length

values (:owner_id, :video_url :vid_length, :thumbnail_url, :title) 

probably should :

/* $vid_length = gmdate("h:i:s", $ytarr['length_seconds']); */ $query = "     insert videos             (owner_id,  video_url,              vid_length,       thumbnail_url,  title)     values (:owner_id, :video_url, sec_to_time(:length_seconds), :thumbnail_url, :title)";  $query = $conn->prepare( $query ); $query->execute(array(         ':owner_id' => $_post['owner_id'],         ':video_url' => $youtube_link,         ':length_seconds' => $ytarr['length_seconds'],         ':thumbnail_url' => (string) $ytarr['thumbnail_url'],         ':title' => (string) $ytarr['title'] )); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -