Skip to content

Instantly share code, notes, and snippets.

View bitkorn's full-sized avatar
💭
do not pull or push

Torsten Brieskorn bitkorn

💭
do not pull or push
View GitHub Profile
@bitkorn
bitkorn / php_baseurl.php
Created August 12, 2017 12:31
Get the base url
<?php
$baseUrl = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['SERVER_NAME'];
@bitkorn
bitkorn / js_stringToUpperFirst.js
Created August 5, 2017 10:39
make the first character to upper letter
function stringToUpperFirst(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
@bitkorn
bitkorn / ZF2_log-SQL-string-with-driver-support.php
Created July 23, 2017 09:42
ZF2 log SQL string with driver-support
<?php
namespace BitkornShop\Table\Basket;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\HydratingResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\AdapterAwareInterface;
/**
@bitkorn
bitkorn / zf2_short_fetch_all_tablex.php
Last active February 24, 2017 09:37
Short way to fetch all from SQL database with ZF2 \Zend\Db\Adapter\Adapter (no ZF2 \Zend\Db\TableGateway\AbstractTableGateway).
<?php
namespace Foo;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Adapter\ParameterContainer;
class A
{
<?php
/**
*
* @param array $data
* @return int
*/
public function insertSomeAndGetLastInsertValue(array $data)
{
$insert = $this->sql->insert();
$insert->values($data);
<?php
$uri = $this->getRequest()->getUri();
$base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
// or
$serverUrlHelper = $this->getServiceLocator()->get('ViewHelperManager')->get('ServerUrl');
$url = $serverUrlHelper($this->url()->fromRoute('some_routename'));
// or in view
echo $this->serverUrl($this->url('some_routename'))
@bitkorn
bitkorn / call_invoke_method_of_a_class_member.php
Created November 26, 2016 17:50
call __invoke() of a class member
<?php
class A
{
/**
*
* @var \SomeNamespace\SomeMember
*/
private $someMember;
@bitkorn
bitkorn / shop_article_join_with_count.sql
Created November 4, 2016 07:59
SELECT tables and JOIN over other and COUNT some table rows
-- without DISTINCT comes false results
SELECT
sa.*,
sac.*,
COUNT(DISTINCT sagr.shop_article_group_relation_id) AS count_group_relation,
COUNT(DISTINCT sai.shop_article_image_id) AS count_image,
COUNT(DISTINCT sar.shop_article_relation_id) AS count_relation,
sasd.*,
COUNT(DISTINCT sasi.shop_article_size_item_id) AS count_size_item,
COUNT(DISTINCT sacomm.shop_article_comment_id) AS count_comment
@bitkorn
bitkorn / Module-PHP-getViewHelperConfig_ViewHelper-with-URL-ViewHelper.php
Last active January 4, 2018 10:56
Use the ZF2 URL ViewHelper in my ViewHelper
<?php
class Module implements Zend\ModuleManager\Feature\ViewHelperProviderInterface
{
public function getViewHelperConfig()
{
return array(
'factories' => [
'simpleAnchor' => function(\Zend\View\HelperPluginManager $hpm) {
$sm = $hpm->getServiceLocator();
@bitkorn
bitkorn / mysql_enum_values.sql
Last active October 29, 2016 09:26
get possible ENUM values from a MySQL table column
-- @return(raw) ('firstenumvalue','secondenumvalue','...')
SELECT
-- cut the word 'enum'
SUBSTRING(COLUMN_TYPE, 5)
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'schemaname'
AND TABLE_NAME = 'tablename'
AND COLUMN_NAME = 'columnname';