Uncaught Error: Call to a member function prepare()

Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\xampp\htdocs\PDO\config\DB.php:21 Stack trace: #0 C:\xampp\htdocs\PDO\config\Student.php(14): DB::prepare('SELECT * FROM t...') #1 C:\xampp\htdocs\PDO\index.php(60): Student->readall() #2 {main} thrown in C:\xampp\htdocs\PDO\config\DB.php on line 21DB.phpclass DB{ private static $pdo; public function connection(){ if(isset(self::$pdo)) { try{ self::$pdo = new PDO ("mysql:host=".DB_HOST.";dbname=",DB_USER,DB_PASS); echo "Conncetion successf...

Prevent "ssi_function=something" from bypassing normal control flow

If you're familiar with SMF, this is how you normally use its server side include://foo.php at http://example/foo.php<?phprequire('./SSI.php'); //assuming we're at SMF's root//...?>But it's hidden to the untrained eye that accessing http://example/foo.php?ssi_function=something will cause ssi_something to be called inside SSI.php, effectively bypassing the foo.php's normal behaviour.I could prepend this before require, but I could avoid a redirection:if(isset($_GET['ssi_function'])){ unset($_GET['ssi_function']); return header('Location: ?' . http_build_query($_...

Why in PHP if you use Mkdir recursive flag do the nest directories not chmod?

I am using mkdir to create normally 2 nested directories for a file structure. The directories it creates are always set to 0755. The code I am using however is. mkdir('path_one/path_two', 0777, true);I have tried then doing chmod('path_one/path_two', 0777);but that only sets the final directory as 0777. What would cause mkdir not to function properly? mkdir is functioning correctly. The intermediate directories created are set based on the current umask. You want something like:umask(0777);mkdir('path_one/path_two', 0777, true); [XXX]From the php manual: The mod...

Handle boolean input in PHP PDO postgres?

Is there a better way to handle boolean inputs for postgres PDO driver in PHP?In PHP PDO casts boolean false to "" and true to "1". And this causes an error like this in some statements:00000 - 7 - ERROR: invalid input syntax for type boolean: ""I am passing my variables to PDOStatement::execute as input array.For now I am using this workaround to pass appropriate string':somevar' => ($this->somevar === true ? 'true' : 'false')Is there a better way?I know about PDOStatement::bindParam with explicit data_type. I want to know the options for passing boolean in param...

What am I doing wrong with my optional PHP arguments?

I have a the following class:class MyClass { public function __construct($id = 0, $humanIdentifier = '') { $this->id = $id; $this->humanID = $humanIdentifier; }}So from my interpretation I should be able to pass either $id or $humanIdentifier to that constructor, neither or both if I wanted. However, when I call the code below I am finding that its the $id in the constructor args being set to hello world and not the $humanIdentifier, despite me specifying the $humanIdentifier when calling the constructor. Can anyone see where I am going wrong?$o =...

Laravel search filter query building with pagination

I have a search form which users enter and I filter out the data then paginate. The problem is I when I paginate Laravel returns entire result $searchFilter = arrray('id'=>true);$building = new Building();if (isset($searchFilter['id'])){ $building->where('id','=', 6);}return $building->paginate(20);In the table there exist only one row with id 6.Laravel returns all the rows of the table.However If I don't paginate it will return only the row with id 6I want it to return paginated with applying the where operation Figured out the answer. I should append it to ...

Custom Font issue in DomPDF latest version 0.8.2

I am using composer installation of DomPDF. so i can't use custom font. I have used font-face option but font is not applying in PDF.$dompdfOptions->set('fontDir', CSSPATH);// for default fonts$dompdfOptions->set('fontDir', FONTSPATH);// for custom fonts$dompdfOptions->set('defaultMediaType', 'all');$dompdfOptions->set('isFontSubsettingEnabled', true);$dompdf = new Dompdf($dompdfOptions);but font is not apply.if i following style:"font-family: Georgia;" // Georgia is examplenot working but if i use"font: 24px Georgia;"font is working but if i add font styles lik...

How to make composer update only files in composer.lock/json and not pull new versions

We are keeping the composer.json/composer.lock in our repository and using composer to update the dependencies. We have a githook for post-checkout to do a composer update. If there is a new version of one of our dependencies or dependencies dependencies it will download the update and change the composer.lockThe problem is that I don't want this because I'll have two developers committing the lock files and there will be needless conflicts.What I would like is to have the composer update be a manual process, commit the composer.lock with the specific versions, and have c...

move_uploaded_file error for new folder

I have a folder in my server where I am uploading file using a php script with the function move_uploaded_file. Now i have created another folder under the same directory and I want to do the same for it.I have set all the permission to read , write and execute(777). But when I try to upload a file to the new folder it shows this error."move_uploaded_file(/var/www/html/HV/tag/human_wal_r.wav): failed to open stream: Permission denied"I am posting my code here. <?php// Path to move uploaded files //$target_path = ""; if(isset($_FILES['fileUp']['name'])){ $fileName= ...

FPDF - Generate multiple pdf in a single creation

I am trying to generate multiple (in cluster) pdf reports using fpdf in a single click in a php form.The test_center is the cluster of separate reports. When the submit button is clicked, it will call the php file of fpdf. And my codes aren't working yet. So far in my php:<?php$program="select distinct test_center from sa_sase_result where school_year = '$content' ";$prog=mysql_query($program);while($row = mysql_fetch_array($prog)){ echo '<option>' .$row['test_center'] . '</option>'; } $message = null;if($_SERVER["REQUEST_METHOD"] == "POST") { ...

Difference between PHP default PDF and FPDF

I am trying out PDF creation in my project. My problem statement is "to club a couple of pdf's into one single pdf"I want to know why people are preferring FPDF everywhere. Doesn't PHP's default PDF module supports the same problem? Is there any difference is speed of creation or size of file created? The default PDF lib built in to PHP has limited formatting requirements such as simple text, images, colors and can become quite verbose to use. The reason for FPDF's popularity is its high-level abstractions which make coding quicker and more concise. Furthermore, there ...

How to set TimeOut for execution the query from PHP Sqlsrv

How do I set the TimeOut for EXEC the Query or Stored Procedure in SqlSrv PHPBecause i am using PHP to call SQL-Server Stored Procedure.For ex"EXEC SP_Name"some times its taking too long time, so the PHP page shows 500 Internal server error.If possible to set the time limit the SP was stopped then i show the error description etc...how do i fix this issue?Thanks in Advance. in your php.ini file set max_execution_time = 60--or whatever time you wishRefer This Link for more details [XXX]The @Jayasurya Satheesh's answer refers to the time of any php execution time, but n...

Get all permutations of a PHP array?

Given a PHP array of strings, e.g.: ['peter', 'paul', 'mary']How to generate all possible permutations of elements of this array? i.e.:peter-paul-marypeter-mary-paulpaul-peter-marypaul-mary-petermary-peter-paulmary-paul-peter function pc_permute($items, $perms = array()) { if (empty($items)) { echo join(' ', $perms) . "<br />"; } else { for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $newperms = $perms; list($foo) = array_splice($newitems, $i, 1); array_unshift($newperms, $foo...

performance on iterations in PHP

Can someone tell me about this performance issueI've got 2 arrays, I need to pick 5 numbers from these 2 arrays and work on the logicthe first array has got 5 number, out of which I need to pick 3 numbersand the second array has got 4 numbers, out of which I need to pick 2 numberso taking this into consideration 5c3 - 10 and 4c2 - 6which means 60 iterations for a single caseIs the method I'm approaching the right way??is there any performance issue on this type of iterations ?? If you have to go through the whole array and pick numbers, then there is no optimization for ...

Post Data is not recieved on destination URL

I had a scenario in which a data on form in http://www.omsite.com to be posted on other website say http://www.hissite.com/myfolderNow whenever the data was being posted, rather then getting posted or getting Status Code 200 I was getting 301 Status code for permanent redirect and hence data was not getting posted.Checking the destination URL I changed it from http://www.hissite.com/myfolder to http://www.hissite.com/myfolder/, yes, I added only a slash after /myfolder and there I got the successful response.i need some help in understanding how just adding a forward slash ...

PHP Send Email, HOST Address not Match Domain Address detected as spam mail

I am having some problem on sending email through my company's website.My company is using an Exchange Server for mailing. Therefore, the email sent from my website HOST address not match the DOMAIN address and yahoo detected my mail as a spam or some mail service blocked and rejected. Received-SPF: none (domain of xxxxx.com does not designate permitted sender hosts)Php Mailer return the following: SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP connect() failed. Mailer Error: SMTP connect() failed.i would like to prevent spam and able to send ema...

Page 1 of 1654  |  Show More Pages:  Top Prev Next Last