Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in demo.mysqli.php help #270

Closed
romanoh opened this issue Oct 10, 2020 · 12 comments
Closed

Error in demo.mysqli.php help #270

romanoh opened this issue Oct 10, 2020 · 12 comments

Comments

@romanoh
Copy link

romanoh commented Oct 10, 2020

imagem

i am using demo.mysqli.php, and an error apears, is something i did wrong? please

looking around maybe something to do with UTF8 ?

@JamesHeinrich
Copy link
Owner

I would suspect it's UTF8-related. How are the fields (especially comments_all) defined in your database table (test_xml ?)
Can you provide a SHOW CREATE TABLE <tablename> to show the structure?

@romanoh
Copy link
Author

romanoh commented Oct 10, 2020

CREATE TABLE `test_xml` (
 `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `filename` text NOT NULL,
 `last_modified` int(11) NOT NULL DEFAULT 0,
 `md5_file` varchar(32) NOT NULL DEFAULT '',
 `md5_data` varchar(32) NOT NULL DEFAULT '',
 `md5_data_source` varchar(32) NOT NULL DEFAULT '',
 `filesize` int(10) unsigned NOT NULL DEFAULT 0,
 `fileformat` varchar(255) NOT NULL DEFAULT '',
 `audio_dataformat` varchar(255) NOT NULL DEFAULT '',
 `video_dataformat` varchar(255) NOT NULL DEFAULT '',
 `audio_bitrate` float NOT NULL DEFAULT 0,
 `video_bitrate` float NOT NULL DEFAULT 0,
 `playtime_seconds` varchar(255) NOT NULL DEFAULT '',
 `tags` varchar(255) NOT NULL DEFAULT '',
 `artist` varchar(255) NOT NULL DEFAULT '',
 `title` varchar(255) NOT NULL DEFAULT '',
 `remix` varchar(255) NOT NULL DEFAULT '',
 `album` varchar(255) NOT NULL DEFAULT '',
 `genre` varchar(255) NOT NULL DEFAULT '',
 `comment` text NOT NULL,
 `track` varchar(7) NOT NULL DEFAULT '',
 `comments_all` longtext NOT NULL,
 `comments_id3v2` longtext NOT NULL,
 `comments_ape` longtext NOT NULL,
 `comments_lyrics3` longtext NOT NULL,
 `comments_id3v1` text NOT NULL,
 `warning` longtext NOT NULL,
 `error` longtext NOT NULL,
 `track_volume` float NOT NULL DEFAULT 0,
 `encoder_options` varchar(255) NOT NULL DEFAULT '',
 `vbr_method` varchar(255) NOT NULL DEFAULT '',
 PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

@JamesHeinrich
Copy link
Owner

Could you please try adding this line around line 48
mysqli_set_charset($con, 'utf8');
and let me know if that helps?

@romanoh
Copy link
Author

romanoh commented Oct 10, 2020

I am sorry still the same.

JamesHeinrich added a commit that referenced this issue Oct 14, 2020
Database inserts would fail with binary data into LONGTEXT fields (change to LONGBLOB)
#270
@JamesHeinrich
Copy link
Owner

I've found the cause of the problem -- the database fields for comments_all (and similar) were defined as LONGTEXT which is fine most of the time, until you try inserting binary data (such as cover art) then you get errors as you did. I have changed the table definition from LONGTEXT to LONGBLOB and that should fix the problem.

Fixed in 10bfeed

@romanoh
Copy link
Author

romanoh commented Oct 14, 2020

Thank you it worked.

@JamesHeinrich also, can it be added to the database the cover art, to put the image in an webpage?

@JamesHeinrich
Copy link
Owner

Cover art is already included in the comments_all field in the database, that was the source of the error with LONGTEXT (instead of LONGBLOB). If you unserialize comments_all and look under picture you will find whatever images are available. You can look at demo.browse.php for some sample code for how to display them inline in a webpage as base64.

@romanoh
Copy link
Author

romanoh commented Oct 18, 2020

@JamesHeinrich I am sorry, i have search for 3 days, and cannot display the image in a webpage, i have tried everything, i now its not in the area of you program, just a little help please. i have tried everything: this is just some examples: https://i.imgur.com/lIhviAF.png

@JamesHeinrich
Copy link
Owner

JamesHeinrich commented Oct 21, 2020

You would need to walk through the array of picture(s) that may (or may not) be present.

// data is stored in database cache table using PHP's serialize function, must unserialize before using:
$row['comments_all'] = unserialize($row['comments_all']);
if (!empty($row['comments_all']['picture'])) {
	echo 'Found '.count($row['comments_all']['picture']).' pictures:<br>';
	foreach ($row['comments_all']['picture'] as $picturedata) {
		if (!empty($picturedata['data']) && !empty($picturedata['image_mime'])) {
			echo '<img src="data:'.$picturedata['image_mime'].';base64,'.base64_encode($picturedata['data']).'" width="'.$picturedata['image_width'].'" width="'.$picturedata['image_height'].'"><br>';
		}
	}
}

@romanoh
Copy link
Author

romanoh commented Oct 21, 2020

@JamesHeinrich Thank you for the answer.
But still nothing is showing.

and if i echo: echo $row['comments_all']['picture']['data'];
it shows an error :
imagem

i think it cant find the ['picture'] and ['data'].

But if i put just echo $row['comments_all']; it shows something:

imagem

@JamesHeinrich
Copy link
Owner

Ah, yes, of course, the stored in the database is serialized, need to unserialize it first. I have edited my above comment to add this at the top:

// data is stored in database cache table using PHP's serialize function, must unserialize before using:
$row['comments_all'] = unserialize($row['comments_all']);

@romanoh
Copy link
Author

romanoh commented Oct 21, 2020

Thank you friend, you are wonderful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants