Site Tools


Hotfix release available: 2026-07-14b "Mort". upgrade now! [57.2] (what's this?)
onny:notizen:programmierung

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
onny:notizen:programmierung [2026/03/17 14:33] – [javascript] 10.250.0.1onny:notizen:programmierung [2026/08/18 11:23] (current) – [mariadb / mysql] fdc9:281f:4d7:9ee9::1
Line 523: Line 523:
  
 ===== php ===== ===== php =====
 +
 +printf string
 +
 +<code php>
 +printf("cleaning criteria: %s\n", $config['filterCriteria']);
 +</code>
 +
 +print array
 +
 +<code php>
 +$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
 +print_r($a);
 +</code>
 +
 +filter array only unique items
 +
 +<code php>
 +$userIds = array_unique($userIds);
 +</code>
 +
 +append to array
 +
 +<code php>
 +$fruits = ['apple', 'banana'];
 +$fruits[] = 'orange'; 
 +</code>
 +
 +assosiative array / dictionary
 +
 +<code php>
 +$myResult["ids"] = [123, 125, 127];
 +</code>
 +
 +datetime object, convert to string
 +
 +<code php>
 +$date = new \DateTime('1990-01-01');
 +$dateString = $date->format('d.m.Y');
 +</code>
 +
 enable debugging / error log enable debugging / error log
 +
 <file - /etc/php/conf.d/debug.ini> <file - /etc/php/conf.d/debug.ini>
 display_startup_errors = true display_startup_errors = true
Line 536: Line 577:
 chmod a+w+r /var/log/php-errors.log chmod a+w+r /var/log/php-errors.log
 </code> </code>
 +
 foreach loop foreach loop
 +
 <code php> <code php>
 foreach($this->service->findAll($this->userId) as $station) { foreach($this->service->findAll($this->userId) as $station) {
Line 546: Line 589:
 } }
 </code> </code>
 +
 get array length get array length
 +
 <code php> <code php>
 var_dump(count($a)); var_dump(count($a));
Line 552: Line 597:
  
 get type of variable get type of variable
 +
 <code php> <code php>
 foreach($data as $episode) { foreach($data as $episode) {
Line 559: Line 605:
  
 convert string to int convert string to int
 +
 <code php> <code php>
 intval("12345"); intval("12345");
Line 569: Line 616:
 </code> </code>
  
 +
 +define class, create object
 +
 +<code php>
 +class Calendar {
 +    private array $data;
 +
 +    public function __construct(array $data) {
 +        $this->data = $data;
 +    }
 +
 +    public function getUserId(): string {
 + $principalUri = $this->data['principaluri'];
 + $principalUriParts = explode('/', $principalUri);
 + $user = end($principalUriParts);
 +        return $user;
 +    }
 +
 +    public function getDisplayName(): string {
 +        return $this->data['displayname'];
 +    }
 +
 +    public function __debugInfo(): array {
 +        // keeps print_r() useful
 +        return $this->data;
 +    }
 +}
 +
 +private function fetchCalendarById(int $calendarId) {
 + $query = $this->dbConnection->getQueryBuilder();
 + $query->select('*')
 + ->from('calendars')
 + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId, IQueryBuilder::PARAM_INT)));
 + $result = $query->executeQuery();
 + $calendar = $result->fetch();
 + $result->closeCursor();
 +
 + if (empty($calendar)) {
 + return false;
 + }
 +
 + return new Calendar($calendar);
 +}
 +</code>
 +
 +print and debug php database queries
 +
 +<code php>
 +$query->select('id', 'calendarid', 'firstoccurence')
 + ->from('calendarobjects')
 + ->where($filterQuery);
 +
 +printf("SQL: %s\n", $query->getSQL());
 +printf("Parameters: %s\n", print_r($query->getParameters(), true));
 +</code>
 +
 +check if array key exists (avoid undefined warning) via "null casting"
 +
 +<code php>
 +if ($config['listCalendars'] ?? false) {
 +</code>
 ==== nextcloud app dev ==== ==== nextcloud app dev ====
 logging, available methods: emergency, alert, critical, error, warning, notice, info, debug logging, available methods: emergency, alert, critical, error, warning, notice, info, debug
Line 601: Line 709:
 </code> </code>
  
 +logging
 +
 +<code php>
 +$this->logger->debug('Running actual SQL query {sql} with parameters {params}', [
 + 'sql' => $query->getSQL(),
 + 'params' => print_r($query->getParameters(), true),
 + 'app' => 'cleanup',
 +]);
 +</code>
 ==== wordpress ==== ==== wordpress ====
 registering menus registering menus
Line 772: Line 889:
 </code> </code>
  
-==== mysql ====+==== mariadb / mysql ==== 
 + 
 +select column and sort alphabetically 
 + 
 +<code> 
 +SELECT user_id 
 +FROM oc_user_oidc 
 +ORDER BY user_id ASC; 
 +</code>
  
 delete specific row delete specific row
 +
 <code> <code>
 delete from oc_storages where numeric_id=58; delete from oc_storages where numeric_id=58;
Line 780: Line 906:
  
 remove user remove user
 +
 <code sql> <code sql>
 DROP USER 'bloguser'@'localhost'; DROP USER 'bloguser'@'localhost';
Line 785: Line 912:
  
 adjust permissions to table adjust permissions to table
 +
 <code sql> <code sql>
 CREATE USER 'ninja'@'http.pi' IDENTIFIED BY '****'; CREATE USER 'ninja'@'http.pi' IDENTIFIED BY '****';
Line 798: Line 926:
 </code> </code>
  
 +sort column by timestamp and convert to datetime
 +
 +<code sql>
 +SELECT
 +    `id`,
 +    `calendarid`,
 +    FROM_UNIXTIME(`firstoccurence`) AS firstoccurence,
 +    FROM_UNIXTIME(`lastoccurence`)  AS lastoccurence
 +FROM `oc_calendarobjects`
 +WHERE (`lastoccurence` < 1606694400)
 +  AND (`firstoccurence` > 0)
 +  AND (`componenttype` = 'VEVENT')
 +ORDER BY `lastoccurence` DESC;
 +</code>
onny/notizen/programmierung.1773758036.txt.gz · Last modified: by 10.250.0.1