3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Classes_DbConnection { private $_host = 'localhost'; private $_user = 'root'; private $_pass = 'mysql1z3l'; private $_dbname = 'corptv'; private $_conn = null; private static $_instance = null; private function __construct() { $this->_conn = mysql_connect($this->_host, $this->_user, $this->_pass) or die(mysql_error()); mysql_select_db($this->_dbname, $this->_conn) or die(mysql_error()); mysql_set_charset(utf8); } public static function getInstance() { if (self::$_instance === null) { self::$_instance = new self; } return self::$_instance; } public static function getByQuery($sql) { $query = mysql_query($sql); $result = array(); while($row = mysql_fetch_assoc($query)) { $result[] = $row; } return $result; } public static function getUniqueByQuery($sql) { $resultado = self::getByQuery($sql); if (count($resultado) == 0) { throw new Exception('Elemento no encontrado'); } return $resultado[0]; } public static function executeQuery($sql) { return mysql_query($sql); } function __destruct() { mysql_close($this->_conn); } } ?> <?php $conn = Classes_DbConnection::getInstance(); $fileNumber = 0; // Read directory files into array $dirPath = '../media_data'; $dirFiles = array(); if ($handle = opendir($dirPath)) { while ($file = readdir($handle)) { $pathInfo = pathinfo($file); if (!is_dir("../media_data/" . $pathInfo['basename'])) { // Get media id, if there is one $idMedia = 0; $splitFilename = explode('_', $pathInfo['filename']); if($splitFilename[0] = '000' && is_numeric($splitFilename[1])) { $idMedia = $splitFilename[1]; } else if($splitFilename[0] = '000' && $splitFilename[0] = 'richtext' && is_numeric($splitFilename[2])) { $idMedia = $splitFilename[2]; } $pathInfo['filesize'] = filesize($dirPath . '/' . $file); $dirFiles[$idMedia][] = $pathInfo; } } } $clientsMedias = array(); foreach ($dirFiles as $idMedia => $files) { if ($idMedia != 0) { // @TODO: Code to avoid processing a files more than once $mediaClients = $conn->getByQuery(" SELECT mrc.id_media, mrc.id_client, mrc.status, mr.title, mr.media, mr.filename, mr.filenamePreview, mr.filenameImage FROM dw_media_resources_clients mrc inner join dw_media_resources mr on mrc.id_media = mr.id WHERE id_media = {$idMedia} "); if (!empty($mediaClients)) { foreach($mediaClients as $media) { $clientsMedias[$media['id_client']][$media['id_media']] = $media; $clientsMedias[$media['id_client']][$media['id_media']]['files'] = $files; } } } } ?> <pre> <?//= print_r($clientsMedias) ?> </pre> <? ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta http-equiv="Content-Language" content="en"/> <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" /> <title>Izel Application Reports</title> <meta name="title" content="Izel Application Reports"/> <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'> <link rel="shortcut icon" href="images/favicon.png" /> <!-- css --> <link rel="stylesheet" href="css/normalize-custom.css" type="text/css" /> <link rel="stylesheet" href="css/styles.css" type="text/css" /> <!-- js --> <script src="js/jquery-1.8.2.min.js"></script> <script src="js/modernizr.js"></script> <script src="js/functions.js"></script> </head> <body> <div class="placer"> <h1>Storage Report</h1> <? foreach ($clientsMedias as $clientId => $clientMedia) { $clientTotalFilesize = 0; $clientTotalFilenumber = 0; ?> <!-- <h2><?= $clientId ?></h2> --> <? foreach ($clientMedia as $media) { $media_type; if($media['media'] == 2 /* Video */){ $media_type = '&#127916;'; } else if($media['media'] == 5 /* Article */ ){ $media_type = '&#59185;'; } else if($media['media'] == 4 /* Image */ ){ $media_type = '&#127748;'; } else if($media['media'] == 3 /* Audio */ ){ $media_type = '&#127925;'; } else if($media['media'] == 6 /* Rich text */ || $media['media'] == 7 /* Blog post */){ $media_type = '&#128240;'; } else if($media['media'] == 1 /* Other */ ){ $media_type = '&#128229;'; } ?> <!-- <table class="report"> <tr> <th class="cell_icon"><i><?=$media_type?></i></th> <th class="cell_title" colspan="3">ID #<?= $media['id_media'] ?> &middot; <?= $media['title'] ?></th> </tr> --> <? foreach ($media['files'] as $fileNumber => $mediaFile) { $filesize = $mediaFile['filesize'] / 1024 / 1024; $clientTotalFilesize += $mediaFile['filesize']; $clientTotalFilenumber += 1; ?> <!-- <tr> <td class="cell_icon icon_success"><i>&#10003;</i></td> <td class="cell_filename"><?= $mediaFile['basename'] ?></td> <td class="cell_filesize"><?= $filesize ?></td> <td>Status</td> </tr> --> <? } ?> <!-- </table> --> <? } ?> <table class="report"> <tr> <th class="cell_icon"><i>&#128203;</i></th> <th class="cell_title" colspan="3">CLIENT ID #<?= $clientId ?> &middot; Nombre de cliente</th> </tr> <tr> <td class="cell_icon"><i>&#57349;</i></td> <td class="cell_filename"><?= $clientTotalFilenumber ?> Archivos</td> <td class="cell_filesize" colspan="2"><?= $clientTotalFilesize / 1024 / 1024 ?> Mb.</td> </tr> </table> <? } ?> </div> </body> </html>
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /in/BIO3B:14 Stack trace: #0 /in/BIO3B(21): Classes_DbConnection->__construct() #1 /in/BIO3B(54): Classes_DbConnection::getInstance() #2 {main} thrown in /in/BIO3B on line 14
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Fatal error: Call to undefined function mysql_connect() in /in/BIO3B on line 14
Process exited with code 255.