0
This script is used together with Coppermine Gallery to show the last albums created in the gallery. However, it does not seem to work with PHP 7. When strings are kept in the old format (mysql_connect), the error given is as follows:
Fatal error: Uncaught Error: Call to Undefined Function mysql_connect() in /home/gustavoj/public_html/lauramarano.com.br/galeria/api.php:8 Stack trace: 0 {main} thrown in /home/gustavoj/public_html/lauramarano.com.br/galeria/api.php online 8
And when changed to mysqli_connect, here is the error:
Warning: mysqli_select_db() expects Parameter 1 to be mysqli, string Given in /home/gustavoj/public_html/lauramarano.com.br/galeria/api.php online 10
Error connecting to database
My question is, what is the best way to update this script. And if there is a way to update this script, because it is amazing and helps a lot in front-end development. Follow the code of the script.
<?php
require_once('include/config.inc.php');
header("Content-type: application/x-javascript");
$connect = mysqli_connect($CONFIG['dbserver'],$CONFIG['dbuser'],$CONFIG['dbpass'])
or die('Erro ao conectar ao servidor');
$connect_db = mysqli_select_db($CONFIG['dbname'], $connect)
or die ('Erro ao conectar ao banco de dados');
$resultado = mysqli_query("SELECT * FROM `cpg_albums` ORDER BY `cpg_albums`.`aid` DESC LIMIT 0 , 12", $link)
or die('Nenhum album encontrado com esta query');
echo 'document.write(\'';
if(mysqli_num_rows($resultado) == 0){
echo 'Nenhum álbum cadastrado';
} else { echo '<div id="postsgall"> ';
while($row = mysqli_fetch_array($resultado)){
echo ' ';
$album_id = $row['aid'];
$subresult = mysqli_query("SELECT * FROM `cpg_pictures` where aid=$album_id order by pid DESC LIMIT 0, 20");
if(mysqli_num_rows($subresult) == 0){
$album_img = "http://lauramarano.com.br/galeria/images/thumbs/thumb_nopic.png";
} else {
while($subrow = mysqli_fetch_array($subresult)){
$album_img = "http://lauramarano.com.br/galeria/albums/".$subrow['filepath'].'normal_'.$subrow['filename'] .$subrow['datebrowse'];
}
}
echo '<div><div class="postsg1"><div class="title">'.$row['title'].' </div><a href="http://lauramarano.com.br/galeria/thumbnails.php?album='.$album_id.' "><img src="http://lauramarano.com.br/wp-content/themes/lmbr16/timthumb.php?src='.$album_img.'&w=164&h=223&zc=1" alt="" /></a> </div></div>';
echo '';
}
} echo '</tr></div>';
echo '\');';
?>
That’s because the parameters are reversed! mysqli_select_db ( mysqli $link , string $dbname )
– NoobSaibot