Jump to content

php error


map200uk

Recommended Posts

hi, after running my recursive scanner on a large number of files, to be catalogued, for my media system, i get the following error:

 

 

Invalid query: Got a packet bigger than 'max_allowed_packet' bytes

 

i assume this is because there is too much data being echoed back ? is there any way to fix this, i need to be able to scan directories with a lot of files totalling several gig,

 

i thought

 

..perhaps not echo anything, so the script doesnt return anything (not sure if it would change anything)

 

or b ...can i change this value in the php.ini?

 

thanks

 

map

Link to comment
Share on other sites

the code is:

 

ive had a read about the error-still not sure why it occurs

 

<?php
include 'oggtest.php';	
function findMusic($dir) {
     $musicList = array();
     $dirHandle = opendir($dir);
     $store="/opt/lampp/htdocs/mp3/";
     while (($file = readdir($dirHandle)) !== FALSE) {

     echo "<br>\n$file";
     echo "<br>\n $dir";
          if ($file == "." || $file == "..") continue;
          if (is_dir($dir . "/" . $file)) 
         {
                echo "<br>full dir \n $dir \n $file ";

                if(is_link($dir) || (is_link($file)))
                {       echo "<br>symlink found , ignoring symlink!!!";
                        echo "<br>$dir./$file \n is a symlink";
                        echo "<br>Symlink found on \n $file in \n $dir";

         } else {
                  $musicList=array_merge($musicList, findMusic($dir . "/" . $file));

        }
             }

          $extension = end(explode(chr(46), $file));
         // print $extension;

      /* if(is_link($file))
       {
       echo "<br>file is a symlink";
       } else {
       */

if(is_link($dir."/".$file))
       {
       echo "<br>$dir./.$file is a symlink!";

      } else {
       if (strtolower($extension) == "mp3" || strtolower($extension)== "ogg")
     
        {

        if(is_link($store.$file))
        { echo "<br>Symlink for \n $dir.$file already exists<br>";
        } else {
        echo "<br>Creating symlink for \n $file in \n $store";


        symlink($dir."/".$file,$store.$file);
        $link=$store.$file;
echo "<br>link is equal to \n $link";
     
   //$musicList[] = $dir . "/" . $file;
        $musicList[]=$link;

echo "<br> dir equal to \n $dir , file is \n $file";
        echo "<br> Loation of file aaaaaaaaaaaaaa";
        echo "<br> Symlink for \n $file is \n $store.$file";
        echo "<br> Symlink created location = $store.$file";
        $linkuse=str_replace("/opt/lampp/htdocs/","/../../../",$link);
        echo "<br>linkuse is equal to \n $linkuse";
echo "<br>";
        echo "<br>";
        echo "<br> VALUE EEEEEEE \n";
        echo $linkuse;
        $musicPath[]=$linkuse;
        }
        } 

       
          
     }

}
     closedir($dirHandle);
     return $musicList;

}
   

echo "<br><b> Please type in the directory you wish to scan for audio!<br></b>";
echo "<br><b> Note, permissions need to allow user nobody to acces the dir, else you will get errors!";
echo "<form action=$_SERVER[php_SELF]?page=finddir&action=scan method=POST><input type=text name=dir>";
echo "<input type=submit name=submit value=submit></form>";

include 'ID3v1x.php';

function addSong($type)
{

global $db;
global $ID3;
global $test;
global $value;
global $path;
if($type=="mp3")
{
$size=filesize($value);
echo "<br>song has a size of $size)";
echo "<br>mpfweeeeee";
print_r($ID3);
$title=$ID3->title;
$artist=$ID3->artist;
$genre=$ID3->genre;
$year=$ID3->year;
$album=$ID3->album;
$comment=$ID3->comment;
$track=$ID3->track; 


}elseif($type="ogg")
{
$size=filesize($value);
echo "<br>ogg filesize \n $size";
print_r($test);
$title=$test['Title'];
$artist=$test[Artist];
$album=$test[Album];
$year=$test[Date];
$comment=$test[Comment];
$track=$test[Tracknumber];
$genre=$test[Genre];



echo "OGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG";
}




$db->query("SELECT * FROM  Song WHERE SongTitle='$title' AND Path='$value'");
                $db->numResults();
                echo "\n <br> Resource ID: $db->result";

                if($db->rows > 0) // if the rows for the query > 0 we have a match, so we insert a record into song table
                                                        // using the albumID found from the query
                {
                        echo "<br>Entry with the same title and file path already added to database!<BR>";

                } else {

                echo "checking to see if album added";
                $db->query("SELECT * FROM album WHERE AlbumName='$album'");
                $db->numResults();
                if($db->rows>0){
                echo "we have a match";
                echo "\n <br> Lets use the current ID and insert the record";
echo "<br> Album ID : --- $db->albumID \n && Resource ID : -- $db->rows";
                $db->query("INSERT INTO Song VALUES ('NULL', '$title', '$year', '$genre', '$value', '$db->albumID','NULL','$path','$comment','$track','$type','$size')");


                } else {
                $db->query("INSERT INTO album VALUES ('NULL','$album','$artist')");
                echo "<br> New file found \n $ID3->path";
                echo "<br>Looks like the album is not added<br>";
                printf("Last inserted record has id %d\n", mysql_insert_id());
                $last_id = mysql_insert_id(); // set the last insert id on mysql (last auto increment id) to $last_id

                echo "<br> New Album inserted...ID: $last_id";
        echo "<br> Now time to insert song entry...";
        $db->query("INSERT INTO Song VALUES ('NULL','$title','$year','$genre','$value','$last_id','NULL','$path','$comment','$track','$type','$size')");  // insert th$
                }
}
// insert data into song table if we found an ID, the tag data i.e. NULL for ID (auto inc), title, year, genre
// path and album id

//$db->getResults("MYSQL_BOTH");












}
if($_POST[dir]!="")
{


//print_r(findMusic("$_POST[dir]"));



//print_r($_POST);
$test=findMusic("$_POST[dir]");

//print_r($test);

$ID3= new ID3v1x();
include 'db.php';

$db = new db();
$link = $db->connect("localhost","monty","some_pass");
$i=0;
foreach ($test as $value) {
   echo "<br><br><b>MP3 found => \n $value</b>";
        $i=$i+1;
echo "<br> \n $i";
if(strstr($value,"ogg"))	
{
echo "OGG FOUND";
echo "<br>$value \n is ogg";
$test=oggdata($value);
echo "<br><br><br><br>";
$title=$test['Title'];
$artist=$test[Artist];
$album=$test[Album];
$year=$test[Date];
$comment=$test[Comment];
$track=$test[Tracknumber];
$genre=$test[Genre];

       		echo "...::::: : File : $value       :::::...<br>";
                echo "...::::: : : ----------------------------------<br>";
                echo "...::::: : : Header :    :::::...<br>";
                echo "...::::: : : Title : $title  :::::...<br>";
                echo "...::::: : : Artist : $artist:::::...<br>";
                echo "...::::: : : Album : $album  :::::...<br>";
                echo "...::::: : : Year : $year    :::::...<br>";
                echo "...::::: : : Comment :$comment :::::...<br>";
                echo "...::::: : : Track : $track  :::::...<br>";
                echo "...::::: : : Genre : $genre  :::::...<br>";
                echo "...::::: : : ----------------------------------";

addSong(ogg);
print_r($test);
}elseif(strstr($value,"mp3"))
{
echo "<br>mp3 yes yes yes u know it";
  if($ID3->readtag($value) == true)
  //{
                echo "...::::: : File : $mp3_file       :::::...<br>";
                echo "...::::: : : ----------------------------------<br>";
                echo "...::::: : : ID3v1 : $ID3->tag    :::::...<br>";
                echo "...::::: : : Title : $ID3->title  :::::...<br>";
                echo "...::::: : : Artist : $ID3->artist:::::...<br>";
                echo "...::::: : : Album : $ID3->album  :::::...<br>";
                echo "...::::: : : Year : $ID3->year    :::::...<br>";
                echo "...::::: : : Comment : $ID3->comm :::::...<br>";
                echo "...::::: : : Track : $ID3->track  :::::...<br>";
                echo "...::::: : : Genre : $ID3->genre  :::::...<br>";
                echo "...::::: : : ----------------------------------";

                $path=$value;
    //            echo "<br>path is \n $path";
              $path=str_replace("/opt/lampp/htdocs/","/../../../",$value);
	$ID3->album=addslashes($ID3->album);
	$ID3->title=addslashes($ID3->title);
	$ID3->artist=addslashes($ID3->artist);
	$ID3->comm=addslashes($ID3->comm);

	addSong("mp3");

// echo "<br> new path is \n $path";
               
}
}
}
?>

Link to comment
Share on other sites

its a query giving the error? oh, il try that, and have to see

 

i think it could be something to do with the 's in the queries

and

when i used addslashes/urlencode a LOT of /// bein added? as mentioned in the other post

 

 

 

could thisbe causing the errors?

 

thanks

 

 

 

 

Link to comment
Share on other sites

Yes, the error is caused by a query.  "max_allowed_pakcet" is a mysql configuration parameter.

 

I don't know much about this particular error message, only that it's caused by mysql, and it's related to either long queries or long query results.

 

As for whether or not your encoding is causing the errors, it might be.  Try printing out the query that causes the error and take a look.  Or maybe try something like this:

 

$sql = "SELECT * FROM blah";
print "Length of query is " . strlen($sql) . "<br>";

 

That'll tell you how big your query is, which should give you a clue as to whether or not it's too big.  If that number it prints out is getting into the millions, then you've got problems :)  You might even need to rethink your database design if that's the problem.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.