C3rd
Fastest way to connect to DB with existing .env
Posted: 10 Jul 2024, 14:34pm - WednesdaySeveral projects now I ended up to create a standalone script to do specific task. Loading doctrine would be using lots of resources. I always want to create a lite-weight script to do specific tasks but connecting to the DB is a bit tricky when you are in a framework (symfony + doctrine).
This is how I do it.. Helps a lot doing this way.
RoundCube WebMail plugin: 2-Factor Authentication (2FA)
Posted: 26 Oct 2021, 21:50pm - TuesdayI was looking for a plugin to implement 2FA in my mail server. I found alexandregz/twofactor_gauthenticator but its quite outdated and quirky. Seems not maintained. So I forked it, the foundation is there and just need to improve it.
After few days of work, here's my improved 2FA for RoundCube webmail. Please feel free to use it and it works well with RoundCube v1.5.x
Git Repo: https://github.com/camilord/twofactor_gauthenticator
Symfony 5.2 Command / Console connecting to DBAL
Posted: 8 Feb 2021, 6:51am - MondayI have been searching how my Symfony Command/Console can connect to the database using DBAL. Somehow there's no working solution that its not either deprecated or the solution was lower version of what I am looking for.
So I made my own solution, takes a while but it works.
- I used the Symfony\Dotenv class to read the .env file and get DATABASE_URL value
- Then I created a class to parse the DATABASE_URL value to Driver/Connection class required array structure (see screenshot below, $db_options variable)
- then I instantiate Driver class and feed the parsed array and Driver to Connection (see sample code below)
Filename: DatabaseUrlEnvUtil
/**
* // mysql://root:secret@127.0.0.1:3306/dbname?serverVersion=5.7
*
* Class DatabaseUrlEnvUtil
* @package App\Utils
*/
class DatabaseUrlEnvUtil
{
/**
* @param string $str
* @return array
*/
public static function convertToArray(string $str) {
$breakers = [
/*'driver' => [
'delimeter' => '://',
'position' => 0
],*/
'user' => [
'delimeter' => [':', '//'],
'position' => [1, 1]
],
'password' => [
'delimeter' => [':', '@'],
'position' => [2, 0]
],
'host' => [
'delimeter' => ['@', ':'],
'position' => [1, 0]
],
'dbname' => [
'delimeter' => ['/', '?'],
'position' => [3, 0]
],
'port' => [
'delimeter' => [':', '/'],
'position' => [3, 0]
]
];
$data = [];
foreach($breakers as $key => $breaker) {
$delimeter = isset($breaker['delimeter']) ? $breaker['delimeter'] : null;
$position = isset($breaker['position']) ? $breaker['position'] : 0;
if (is_null($delimeter)) {
continue;
}
if (is_array($delimeter)) {
$tmp_data = $str;
foreach($delimeter as $i => $item) {
$tmp = explode($item, $tmp_data);
$tmp_data = $tmp[$position[$i]];
}
$data[$key] = $tmp_data;
} else {
$tmp = explode($delimeter, $str);
$data[$key] = isset($tmp[$position]) ? $tmp[$position] : null;
}
}
return $data;
}
}
Console/Command Output:
That's it, problem solved.
ASP.Net Core C#: Handling new lines in Razor view
Posted: 21 Mar 2020, 20:52pm - SaturdayI've been programming using PHP for a long time, and its funny I am struggling to do it on ASP.Net Core C#. In PHP, all you need to do is call the function "nl2br()" and that's it.
In this blog, I am reminding myself how to do it in ASP.Net Core C#. There are two ways how to resolve my issue:
I think that's it... Hope for the readers of this post looking for answers like me will help you as well.
POLi Payment Gateway: Why you shouldn't use this option...
Posted: 11 Apr 2016, 1:59am - MondaySelwyn District Council Consents
Posted: 18 Sep 2014, 1:24am - ThursdayAllow postfix to send email with different sender from SMTP account
Posted: 2 Mar 2014, 23:17pm - Sundaypostfix/smtpd[27402]: NOQUEUE: reject: RCPT from unknown[125.123.123.100]: 553 5.7.1 <user@xxx.co.nz>: Sender address rejected: not owned by user user@xxx.co.nz; from=<xxx@xxx.co.nz> to=<xxx@gmail.com> proto=ESMTP helo=<localhost>Edit postfix configuration:
[root@mail ~]# nano /etc/postfix/main.cfChange from:
smtpd_sender_restrictions = permit_mynetworks, reject_sender_login_mismatch, permit_sasl_authenticatedTo:
smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticatedThen restart postfix...
[root@mail ~]# postfix stop postfix/postfix-script: stopping the Postfix mail system postfix/postfix-script: waiting for the Postfix mail system to terminate [root@mail ~]# postfix start postfix/postfix-script: starting the Postfix mail system [root@mail ~]#That's it.. You can now change your from or reply-to in your PHPMailer. :) Hope this helps...
[Solution] JpGraph Error: 25128 The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.
Posted: 6 Dec 2013, 1:04am - FridayJpGraph Error: 25128 The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.Two solutions as I know:
- install the required library
- or simply comment certain line
JpGraph Error: 25049 Font file "/usr/share/fonts/truetype/arialbd.ttf" is not readable or does not exist.Look for jpg-config.inc.php and add these lines:
define('CACHE_DIR','cache/'); define('TTF_DIR','includes/jpgraph/fonts/');Note: Just place the right path where you setup your jpgraph folder Download required JpGraph Fonts: [download id="39"] And that should solve the problems... :) Samples:
PHP + Firebird SQL Installation
Posted: 28 May 2013, 22:20pm - Tuesday- PHP
- Apache
- Firebird (http://www.firebirdsql.org/en/firebird-2-5-2-upd1/)
- php_interbase.dll
- php_pdo_firebird.dll
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_interbase.dll' - The specified module could not be found. in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pdo_firebird.dll' - The specified module could not be found. in Unknown on line 0 PHP 5.4.9 (cli) (built: Nov 21 2012 19:54:46) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend TechnologiesInstall the Firebird... Try again casting a command php -v
C:\Workspace\localhost\vshbdata>php -v PHP 5.4.9 (cli) (built: Nov 21 2012 19:54:46) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend TechnologiesMeaning, the firebird is successfully installed. Second test is create a php script:
<?php foreach(PDO::getAvailableDrivers() as $driver) { echo $driver.'<br />'; } ?>You should see firebird in the list...
BeeCheckout Online Ordering System
Posted: 19 Jun 2024, 16:59pm - WednesdayWhen you own a restaurant or food shop, online presence is highly recommended to increase sales. Ordering online is a must too. Several online ordering providers are in the wild and daunting to choose from. Then, most of them are commission based platform!
Imagine a online ordering system that bill you on fixed price, not commission based, which more profitable on your side? Try BeeCheckout - https://www.beecheckout.com, take control of your sales and say good bye with commission based platform.
Windows: Setting up Apache 2.4.48 and PHP 7.4.20
Posted: 13 Jul 2021, 23:43pm - TuesdayBefore going thru the steps below, you need to download the installers first at http://camilord.com/downloads/Apache2.4.48_PHP7.4.20.zip
Then, just extract the zip which will give you both apache (httpd-2.4.48-o111k-x64-vc15) and php (php-7.4.20-Win32-vc15-x64). They are also in a zip, extract it in "C:\" and rename it like below.
would look like:
C:\Apache24
C:\php
then in apache, go to httpd.conf and edit it.
Add the following lines:
# php 7.4.20 handler
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php .html
LoadModule php7_module "c:/php/php7apache2_4.dll"
PHPIniDir "c:/php"
you can skip this step, you only do this when you have existing apache installation
httpd -k uninstall -n "Apache2.4"
then save it. go to Apache24\bin using CLI or powershell (as administrator) then run:
httpd.exe -k install -n "Apache2.4"
this will install as a service. then to start and stop
httpd -k start
httpd -k stop
or
net start "Apache2.4"
net stop "Apache2.4"
then for PHP, copy the php.ini-development
as php.ini
then adjust the necessary configuration
needed by your application. then since you're in dev mode, add this at the end of the php.ini:
[Xdebug]
zend_extension="C:/php/ext/php_xdebug-3.0.4-7.4-vc15-x86_64.dll"
xdebug.client_port="9003"
xdebug.mode=debug
;xdebug.mode=profile
you can find the file in this folder and make sure you copy that xdebug dll file to C:\php\ext\
then restart the apache…
and if you have changes in your php.ini
on next edit, restart again your apache.
GitLab: docker DNS issue and container already in use
Posted: 6 May 2020, 21:46pm - WednesdayI decided to create another stage to test our API in GitLab CI runner using postman/newman
. I made it work but there are issues from time to time like DNS issue and "container already in use" (see screenshot below). The common error that occurs most of the time is the DNS issue.
In my various experiments, I managed to resolve the `container already in use` issue by adding the container name with commit ID from gitlab.
However, since I implemented the commit ID on the container, the DNS issue reduced from 8/10 fails to 2/10 fails. It still fail time to time, its not perfect but for now its tolerable. I hope there's a better solution.
NZ Companies Register API
Posted: 25 Feb 2018, 3:50am - Sundayuse camilord\NZCompaniesRegister\NZCompaniesRegister; $obj = new NZCompaniesRegister(); $result = $obj->search('blue horn'); print_r($result);Cheers!
MySQL Constraints: Import
Posted: 10 Mar 2015, 2:09am - TuesdayERROR 1217 (23000) at line 128: Cannot delete or update a parent row: a foreign key constraint failsThe solution is add the following line in the beginning of the SQL dump file:
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0That should work.
PHP Deployment Tool: Mage
Posted: 18 Aug 2014, 23:56pm - MondaySymfony2: Install/Create Project
Posted: 30 Jan 2014, 4:10am - ThursdayC:\php>php composer.phar install Warning: This development build of composer is over 30 days old. It is recommended to update it by running "composer.phar self-update" to get the latest version. Composer could not find a composer.json file in C:\php To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section C:\php>php composer.phar self-update Updating to version 0238aaf5ac565a5b896caa79e9ca7e71d2312343. Downloading: 100% C:\php>php composer.phar install Composer could not find a composer.json file in C:\php To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section C:\php>composer install 'composer' is not recognized as an internal or external command, operable program or batch file. C:\php>php composer install Could not open input file: composer C:\php>php composer.phar ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 0238aaf5ac565a5b896caa79e9ca7e71d2312343 2014-01-29 09:12:19 Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version -V Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction -n Do not ask any interactive question. --profile Display timing and memory usage information --working-dir -d If specified, use the given directory as working directory. Available commands: about Short information about Composer archive Create an archive of this composer package config Set config options create-project Create new project from a package into given directory. depends Shows which packages depend on the given package diagnose Diagnoses the system to identify common errors. dump-autoload Dumps the autoloader dumpautoload Dumps the autoloader global Allows running commands in the global composer dir ($COMPOSER_HOME). help Displays help for a command init Creates a basic composer.json file in current directory. install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json. licenses Show information about licenses of dependencies list Lists commands require Adds required packages to your composer.json and installs them run-script Run the scripts defined in composer.json. search Search for packages self-update Updates composer.phar to the latest version. selfupdate Updates composer.phar to the latest version. show Show information about packages status Show a list of locally modified packages update Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file. validate Validates a composer.json C:\php>php composer.phar install Composer could not find a composer.json file in C:\php To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section C:\php>php composer.phar install Loading composer repositories with package information Installing dependencies (including require-dev) - Installing monolog/monolog (1.2.1) Downloading: 100% monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server) monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required)) monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server) Writing lock file Generating autoload files C:\Workspace\localhost\symfony>php.exe c:\php\composer.phar create-project symfony/framework-standard-edition c:\workspace\localhost\symfony\Symfony 2.4.1 Installing symfony/framework-standard-edition (v2.4.1) - Installing symfony/framework-standard-edition (v2.4.1) Downloading: 100% Created project in c:\workspace\localhost\symfony\Symfony Loading composer repositories with package information Installing dependencies (including require-dev) - Installing jdorn/sql-formatter (v1.2.17) Downloading: 100% - Installing psr/log (1.0.0) Loading from cache - Installing twig/twig (v1.15.0) Downloading: 100% - Installing doctrine/lexer (v1.0) Downloading: 100% - Installing doctrine/annotations (v1.1.2) Downloading: 100% - Installing doctrine/collections (v1.1) Downloading: 100% - Installing doctrine/cache (v1.3.0) Downloading: 100% - Installing doctrine/inflector (v1.0) Downloading: 100% - Installing doctrine/common (v2.4.1) Downloading: 100% - Installing symfony/symfony (v2.4.1) Downloading: 100% - Installing symfony/icu (v1.0.0) Downloading: 100% - Installing doctrine/dbal (v2.4.2) Downloading: 100% - Installing doctrine/doctrine-bundle (v1.2.0) Downloading: 100% - Installing kriswallsmith/assetic (v1.1.2) Downloading: 100% - Installing symfony/assetic-bundle (v2.3.0) Downloading: 100% - Installing sensio/framework-extra-bundle (v3.0.0) Downloading: 100% - Installing doctrine/orm (v2.4.1) Downloading: 100% - Installing twig/extensions (v1.0.1) Downloading: 100% - Installing swiftmailer/swiftmailer (v5.0.3) Loading from cache - Installing symfony/swiftmailer-bundle (v2.3.5) Downloading: 100% - Installing monolog/monolog (1.7.0) Loading from cache - Installing symfony/monolog-bundle (v2.5.0) Downloading: 100% - Installing sensio/distribution-bundle (v2.3.4) Downloading: 100% - Installing sensio/generator-bundle (v2.3.4) Downloading: 100% - Installing incenteev/composer-parameter-handler (v2.1.0) Downloading: 100% kriswallsmith/assetic suggests installing leafo/lessphp (Assetic provides the integration with the lessphp LESS compiler) kriswallsmith/assetic suggests installing leafo/scssphp (Assetic provides the integration with the scssphp SCSS compiler) kriswallsmith/assetic suggests installing ptachoire/cssembed (Assetic provides the integration with phpcssembed to embed data uris) kriswallsmith/assetic suggests installing leafo/scssphp-compass (Assetic provides the integration with the SCSS compass plugin) monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server) monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server) monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server) monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server) monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required)) monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server) monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB) Writing lock file Generating autoload files Creating the "app/config/parameters.yml" file Some parameters are missing. Please provide them. database_driver (pdo_mysql): database_host (127.0.0.1): database_port (null): 3306 database_name (symfony): database_user (root): database_password (null): secretkanding mailer_transport (smtp): mailer_host (127.0.0.1): mailer_user (null): mailer_password (null): locale (en): secret (ThisTokenIsNotSoSecretChangeIt): 123456987456321 Clearing the cache for the dev environment with debug true Installing assets using the hard copy option Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework Installing assets for Acme\DemoBundle into web/bundles/acmedemo Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution C:\Workspace\localhost\symfony>
IDE: NetBeans vs phpStorm
Posted: 27 Nov 2013, 20:23pm - WednesdayRoot composer.json requires PHP extension ext-zend-opcache * but it is missing from your system. Install or enable PHP's zend-opcache extension. (Windows 7 or Windows10)
Posted: 10 Feb 2022, 20:28pm - ThursdayIssue:
C:\localhost\projectApp>php composer.phar update
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires PHP extension ext-zend-opcache * but it is missing from your system. Install or enable PHP's zend-opcache extension.
Solution:
Edit your php.ini and add this:
zend_extension=C:/php/ext/php_opcache.dll
then uncomment ...
[opcache]
; Determines if Zend OPCache is enabled
;opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1
That's it! To confirm it, do:
C:\localhost\projectApp>php -v
PHP 7.4.20 (cli) (built: Jun 1 2021 20:31:10) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
with Zend OPcache v7.4.20, Copyright (c), by Zend Technologies
Free Planning Poker
Posted: 12 Jun 2021, 13:26pm - SaturdayHello Agile/Scrum people ...
If you are looking for free planning poker, use http://www.freeplanningpoker.co.nz/ or http://www.freeplanningpoker.site/ or http://www.freeplanning.poker/ and there will be no ads or limitation of 5 users or 5 issues then try to force you to upgrade to premium. The limitation is like it can create 100 issues of each gameplay and of course limit to 8 players, more than that will be a conference already. So 8 users or players, cast a vote and get the score for your issues.
This application is used for team management amd planning for agile team.
git doesn't pull or push: "error: RPC failed; HTTP 502 curl 22 The requested URL returned: 502 Bad Gateway"
Posted: 29 Mar 2020, 19:59pm - SundayI recently encountered a weird error on my repo when I "git push" or "git pull" in Windows 7. But when I tried it on my Mac, Ubuntu & Windows 10, its working fine.
As shown above, that's the error I am getting when I pull/push. I tried the solution from others:
But unfortunately it didn't resolve my problem. Somehow, it did made it a bit faster.
I already tried many things, but I cannot find any solution that works for my problem. I know that the issue is just in my PC, even tried emptying my hosts file still didn't work.
Then a lightbulb popup, maybe I should delete my current repo and checkout again. So I did and resolve my problem. I can pull and push after that.
PHP: about NULL vs 0
Posted: 18 Sep 2017, 20:43pm - Monday$parcelData = []; $jobVarObj = new JobsVarsTable(); $jobVarObj->setDrivers($this->getQueryDriver()); $prime_parcel = $jobVarObj->getVarValue($this->job_id, 'PRIMARY_PARCEL'); ... $q = "SELECT * FROM jobs_parcels WHERE JID = '%d' AND ID != '%d' AND Deleted IS NULL"; $sql = $this->getQueryDriver()->fetchAll($q, [$this->job_id, $prime_parcel]); $parcel_data_list = $sql->getData();In that codes above, the $parcel_data_list is always empty and I know there are 1 row results. 2 hours later... Note: $prime_parcel = null; // if does not exists in the records, will return literal null I just realised that printing vsprintf($q, [ $this->job, $prime_parcel ]) will gave me what I expected because when you sprintf() or vsprintf() the NULL to %d, this will convert to ZERO. But actually when I pass the query to our QueryDriver, %d and %s are actually converted to ? which the NULL become literal NULL in the query. Instead of "SELECT * FROM jobs_parcels JID = '123' AND ID != '0' AND DELETED IS NULL" then becomes "SELECT * FROM jobs_parcels JID = '123' AND ID != NULL AND DELETED IS NULL". So there will be no result. So lesson learn... Solution:
$parcelData = []; $jobVarObj = new JobsVarsTable(); $jobVarObj->setDrivers($this->getQueryDriver()); $prime_parcel = (int)$jobVarObj->getVarValue($this->job_id, 'PRIMARY_PARCEL', 'n'); ... $q = "SELECT * FROM jobs_parcels WHERE JID = '%d' AND ID != '%d' AND Deleted IS NULL"; $sql = $this->getQueryDriver()->fetchAll($q, [$this->job_id, $prime_parcel]); $parcel_data_list = $sql->getData();Then it solves my 2hrs problem!!! Ok that's my entry for half of 2017... hehehe.. Cheers!
Prendstah.com got A+ grade from ssllabs.com
Posted: 15 Dec 2014, 11:09am - MondaySSL Test: https://www.ssllabs.com/ssltest/analyze.html?d=prendstah.com
Code Igniter: Cannot get POST values
Posted: 27 Mar 2014, 22:01pm - Thursday# cd /etc/apache2/mods-enabled/ # locate mod_rewrite /usr/lib/apache2/modules/mod_rewrite.so # touch rewrite.load # nano rewrite.loadAt the file:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.soSave the changes and restart apache. Hope this will help you... Pee coding!
Top PHP Frameworks
Posted: 9 Dec 2013, 20:23pm - MondayPHP and MySQL TimeZone Synchronization
Posted: 5 Nov 2013, 3:00am - Tuesday<?php define('TIMEZONE', 'Australia/Brisbane'); @date_default_timezone_set(TIMEZONE); $dt = new DateTime(); // get time offset $offset = $dt->format("P"); // update mysql timezone mysql_query("SET time_zone='$offset';"); ?>Thanks to Craig Buckler... Reference: http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/