function set_mysql_album_len_function($dbh) { $func_query = "\n DROP FUNCTION IF EXISTS track_len;\n CREATE FUNCTION album_len(s INT)\n RETURNS VARCHAR(16) DETERMINISTIC\n BEGIN\n DECLARE hours, minutes, seconds INT;\n SET hours = s DIV 3600;\n SET minutes = (s MOD 3600) DIV 60;\n SET seconds = s MOD 60;\n IF hours > 0 THEN\n RETURN CONCAT_WS(':', hours, LPAD(minutes, 2, '0'), LPAD(seconds, 2, '0' ));\n ELSE\n RETURN CONCAT_WS(':', minutes, LPAD(seconds, 2, '0' ));\n END IF;\n END\n "; $dbh->exec($func_query); db_message($dbh); }
function get_tracks_sql($album_id) { global $CRUD; $dbh = $CRUD['dbh']; switch (DBENGINE) { case 'mysql': $query = ' SELECT id, album_id, title, track_number, CONCAT_WS( ":", duration DIV 60, LPAD( duration MOD 60, 2, "0" ) ) AS disp_duration FROM track WHERE album_id = ? ORDER BY track_number, id '; break; case 'sqlite3': $query = "\n SELECT \n id, album_id, title, track_number, SEC_TO_TIME(duration) AS disp_duration\n FROM track\n WHERE album_id = ?\n ORDER BY track_number, id\n "; break; default: $query = ''; break; } $sth = $dbh->prepare($query); if ($sth) { $sth->execute(array($album_id)); } else { error("get_tracks_sql: select prepare returned no statement handle (" . db_message($dbh) . ")"); } $err = $sth->errorInfo(); if ($err[0] != 0) { error($err[2]); } return $sth; }
function _db_message($object, $success = TRUE, $record = FALSE, $action = FALSE) { $type = $success ? 'note_success' : 'danger'; $this->messages->{$type}(db_message($object, $success, $record, $action)); }