Warning: pdo_dummy::rowCount() - php

So i tried changing all my MySQL queries in order to use PDO..
After changing, I have some few errors like this..when trying to add a new comment in file.php, annoying thing is the comment is added but this error comes as well..
Warning: pdo_dummy::rowCount() Your last query was unsuccessful and returned FALSE
instead of a fetchable result. See pdo_error() to find out why. - caused by /home/user
/public_html/file.php, line 118, when calling pdo_affected_rows(); in /home/user
/public_html/includes/pdo_mysql.php on line 1068
On line 118 in file.php
if (pdo_affected_rows() == 1)
show_error_msg(T_("COMPLETED"), T_("COMMENT_ADDED"), 0);
else
show_error_msg(T_("ERROR"), T_("UNABLE_TO_ADD_COMMENT"), 0);
On Line 1068 in pdo_mysql.php
function pdo_trigger_error($msg, $level=E_USER_NOTICE) {
// locate source of last pdo_*() invocation
foreach ((debug_backtrace()) as $src) {
// skip any functions in the current file
if (empty($src["file"])) {
$src["file"] = "{main}";
$src["line"] = "-";
}
if ($src["file"] != __FILE__) {
$dir = dirname($src["file"]);
$file = basename($src["file"]);
$msg .= " - caused by $dir/<b>$file</b>, line <b>$src[line]</b>, when calling <a>$src[function]()</a>;";
break;
}
}
// pass on to actual error handler chain
trigger_error($msg, (($level == 1<<14) && (PHP_VERSION < 5.3)) ? E_USER_NOTICE : $level);
}
I'm thinking this error occurs as a result of conflict but not sure...
trigger_error($msg, (($level == 1<<14) && (PHP_VERSION < 5.3)) ? E_USER_NOTICE : $level);
The complete pdo_mysql.php script is here Using PDO_MySQL
Thanks.....

Related

Form upload errors after updating to PHP version 7.3.11 [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Fatal error: Uncaught ArgumentCountError: Too few arguments to function
(6 answers)
Closed 2 years ago.
I have a form that was working normally until our host updated the PHP version to 7.3.11. Now when you try to submit to the form it gives this error message:
Fatal error: Uncaught ArgumentCountError: Too few arguments to
function sl_upload(), 2 passed in
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/question/class.upload.php
on line 331 and exactly 3 expected in
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/lib/lib.upload.php:74
Stack trace: #0
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/question/class.upload.php(331):
sl_upload('/var/tmp/phpU0P...', '/appLms/test/2_...') #1
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/lib/lib.test.php(1106):
Upload_Question->storeAnswer(Object(Track_Test), Array, '1') #2
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/test/do.test.php(1208):
PlayTestManagement->storePage('1', '1') #3
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/test/do.test.php(592):
showResult(Object(Learning_Test), 29) #4
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/class.module/learning.test.php(309):
in /nfs/c07/h03/mnt/113634/domains/myurl.com/html/lib/lib.upload.php
on line 74
I didn't change any of the code. The only thing that changed was the PHP version. As a result, I'm not even sure how to start fixing this.
Here's what's on class.upload.php > line 331
sl_open_fileoperations();
if(!sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile)) {
$savefile = Lang::t('_QUEST_ERR_IN_UPLOAD');
}
sl_close_fileoperations();
} else {
$savefile = Lang::t('_QUEST_ERR_IN_UPLOAD');
}
}
...and here's what's on lib.upload.php > Line 74
function sl_upload( $srcFile, $dstFile, $file_ext) {
$uploadType = Get::cfg('uploadType', null);
// check if the mime type is allowed by the whitelist
// if the whitelist is empty all types are accepted
require_once(_lib_.'/lib.mimetype.php');
$upload_whitelist =Get::sett('file_upload_whitelist', 'rar,exe,zip,jpg,gif,png,txt,csv,rtf,xml,doc,docx,xls,xlsx,ppt,pptx,odt,ods,odp,pdf,xps,mp4,mp3,flv,swf,mov,wav,ogg,flac,wma,wmv,jpeg');
$upload_whitelist_arr =explode(',', trim($upload_whitelist, ','));
if (!empty($upload_whitelist_arr)) {
$valid_ext = false;
$ext=strtolower(substr(strrchr($dstFile, "."), 1));
if($ext!=""){
$file_ext =strtolower(substr(strrchr($dstFile, "."), 1));
}
foreach ($upload_whitelist_arr as $k=>$v) { // remove extra spaces and set lower case
$ext =trim(strtolower($v));
$mt =mimetype($ext);
if ($mt) { $mimetype_arr[]=$mt; }
getOtherMime($ext, $mimetype_arr);
if ($ext == $file_ext) {
$valid_ext =true;
}
}
$mimetype_arr = array_unique($mimetype_arr);
if ( class_exists('finfo') && method_exists('finfo', 'file')) {
$finfo =new finfo(FILEINFO_MIME_TYPE);
$file_mime_type =$finfo->file($srcFile);
}
else {
$file_mime_type =mime_content_type($srcFile);
}
if (!$valid_ext || !in_array($file_mime_type, $mimetype_arr)) {
return false;
}
}
$dstFile =stripslashes($dstFile);
if( $uploadType == "ftp" ) {
return sl_upload_ftp( $srcFile, $dstFile );
} elseif( $uploadType == "cgi" ) {
return sl_upload_cgi( $srcFile, $dstFile );
} elseif( $uploadType == "fs" || $uploadType == null ) {
return sl_upload_fs( $srcFile, $dstFile );
} else {
$event = new \appCore\Events\Core\FileSystem\UploadEvent($srcFile, $dstFile);
\appCore\Events\DispatcherManager::dispatch(\appCore\Events\Core\FileSystem\UploadEvent::EVENT_NAME, $event);
unlink($srcFile);
return $event->getResult();
}
}
Based on that I'm not sure what to change and I don't want to break what was working before.
All the rest of the website is working normally, including PHP functions like logging in. Thanks in advance for any pointers.
Try replacing:
sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile)
with:
sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile, null);
Explanation: the sl_upload function is expecting 3 arguments, and you're passing only 2.
Before PHP 7.1, this only triggered a warning, but since then it's generating a Fatal Error instead.
Since it worked fine for you before (although, it must have triggered a Warning, which probably got logged somewhere unless your error_reporting is very lax), passing null as the third argument should produce the same outcome as it used to.
It would, however, be a better idea to figure out what that function argument is supposed to be used for, as it's marked as required (no default value).

Using rename() which works but giving warning at the same time

OK I'm confused. This code is showing me an error but at same time is doing what I actually needed.
$dir = new DirectoryIterator('./');
foreach ($dir as $filename) {
if (mimes_content_type($filename) == 'txt') {
rename($filename, './txt/'.$filename);
}
}
Warning: rename(txt,./txt/txt.txt): Invalid argument in ./www/session/test.php on line 78
Some advices what i did wrong ?

PHP mkdir doesn't make new directories

I'm trying to make a new directory to handle profile pictures, but every time I upload the image, nothing happens as in the new directory is not created and there are no errors whatsoever. I already checked the Apache error log, but didn't notice any error pertaining to my recent code...
Here's a sample of my code
//profile image upload script
if (isset($_FILES['profile_pics'])) {
if (((#$_FILES["profile_pics"] ["type"] == "image/jpeg" || (#$_FILES["profile_pics"] ["type"] == "image/png") || (#$_FILES["profile_pics"] ["type"] == "image/gif")) && (#$_FILES["profile_pics"] ["size"] < 1048576)) ) // LESS THAN ONE MEGABYTE
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
mkdir("userdata/profile_pics/$rand_dir_name");
else {
}
}
}
You have multiple errors in your PHP, are you sure you did not see any FATAL errors in your apache logs?
Your if query does not close properly
Your else statement is missing a braket
You're suppressing any errors with # - remove them!
Use an absolute path instead of relative path to avoid errors in where you're creating the directory
Here's an example of how it should look:
// array of valid image types
$valid = array( 'image/jpeg', 'image/png', 'image/gif' );
if (isset($_FILES['profile_pics'])) {
// if the file type is in the valid array and the size is less than 1MB
if ( in_array($_FILES['profile_pics']['type'], $valid)
&& ($_FILES["profile_pics"]["size"] < 1048576) )
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
mkdir($_SERVER['DOCUMENT_ROOT'] . "/userdata/profile_pics/$rand_dir_name");
} else {
print( 'too big or not an image.' );
}
}
EDIT
You should also check the mkdir response.. like this:
$ok = mkdir($_SERVER['DOCUMENT_ROOT'] . "/userdata/profile_pics/$rand_dir_name");
if( !$ok )
{
print('error creating directory, check your permissions');
} else {
print('created directory successfully!');
}
Try to add permission.
mkdir("/path/", 0755);

"Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 3 in..."

I've searched other questions but can't find a workable solution. This is a CMS program, I've tried to upload files to any directory and am getting the following the error:
Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 3 in /home/...on line 1017
Here is the code, any suggestions?:
function _IsValidPath($Path)
{ // First check if the path starts with the starting directory
$basePath = preg_replace("/{1,}/", "/", $_SESSION['rootdirectory'] . '/' . // this line (1017) causing the error
$_SESSION["startingdirectory"]);
$sdPos = strpos($basePath, $Path);
if (!is_numeric($sdPos))
{
$sdPos = strpos($Path, $basePath);
}
if(is_numeric($sdPos) && $sdPos == 0)
{
// Make sure it doesn't contain any invalid characters
if(is_numeric(strpos($Path, "..")) ||
(is_numeric(strpos($Path, "./"))) ||
(is_numeric(strpos($Path, "//"))) ||
(is_numeric(strpos($Path, "\\"))) ||
(is_numeric(strpos($Path, "../"))) ||
(is_numeric(strpos($Path, "&"))) ||
(is_numeric(strpos($Path, "*"))) ||
(is_numeric(strpos($Path, " "))) ||
(is_numeric(strpos($Path, "'"))) ||
(is_numeric(strpos($Path, "\?"))) ||
(is_numeric(strpos($Path,"<"))) ||
(is_numeric(strpos($Path, ">"))))
{
return false;
}
else
{
// The path is OK
return true;
}
}
else
{
return false;
}
}
Change it to:
$basePath = preg_replace("#/{1,}/#", "/", $_SESSION['rootdirectory'] . '/' .
$_SESSION["startingdirectory"]);
preg_replace expects the regular expression to be delimited by a character inside the string so that you can specify flags like g or i afterwards (I usually use #). It was treating / as the delimiter. See the preg_replace manual page for more info.
Even still, this code doesn't make much sense, and there is probably a much better way to accomplish what it is supposed to do.
/{1,}/
Looks like you're trying to match 1 or more of nothing.

PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]

I've noticed that the directory on which one of the PHP script is installed have very large error_log file almost of 1GB size, mostly the errors are generated by coding on line 478 and 479.. example of the error from error_log file is below:
PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /home/khan/public_html/folder/ZBall.jar in /home/khan/public_html/folder/index.php on line 478
PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /home/khan/public_html/folder/ZBall.jar in /home/khan/public_html/folder/index.php on line 479
I have the following coding, line 477 to 484
foreach ($mp3s as $gftkey => $gftrow) {
$ftimes[$gftkey] = array(filemtime($thecurrentdir.$gftrow),$gftrow);
$ftimes2[$gftkey] = filemtime($thecurrentdir.$gftrow);
}
array_multisort($ftimes2,SORT_DESC,$ftimes);
foreach ($ftimes as $readd) {
$newmp3s[] = $readd[1];
}
Please help me on this.
Thanks.. :)
The stat failed error would indicate that the file /home/khan/public_html/games/ZBall.jar either doesn't exist, or can't be read due to a permission error. Make sure the file exists in the place PHP is looking, as that seems like the most like cause of the problem.
Since it comes from the array $mp3s, make sure that array contains names of files that exist and modify it if not.
ask for the file before doing something with it. checm my edit:
<?php
foreach ($mp3s as $gftkey => $gftrow) {
if (file_exists($thecurrentdir.$gftrow)) {
$ftimes[$gftkey] = array(filemtime($thecurrentdir.$gftrow),$gftrow);
$ftimes2[$gftkey] = filemtime($thecurrentdir.$gftrow);
}
}
array_multisort($ftimes2,SORT_DESC,$ftimes);
foreach ($ftimes as $readd) {
$newmp3s[] = $readd[1];
}
There is a function on PHP.net site which removes a bug on Windows about filemtime
function GetCorrectMTime($filePath) {
$time = filemtime($filePath);
$isDST = (date('I', $time) == 1);
$systemDST = (date('I') == 1);
$adjustment = 0;
if($isDST == false && $systemDST == true)
$adjustment = 3600;
else if($isDST == true && $systemDST == false)
$adjustment = -3600;
else
$adjustment = 0;
return ($time + $adjustment);
}
source: http://php.net/manual/tr/function.filemtime.php#100692

Categories