Posts

Showing posts with the label php

A Set of Static Analyzers for PHP Code

A static analyzer scans the source code for errors and vulnerabilities and for compliance with the coding standard. The article describes how to install, configure and run static analyzers: PHPStan Psalm PHP_CodeSniffer PHP Coding Standards Fixer PHPMD PHPStan Installation composer require --dev phpstan/phpstan Run vendor/bin/phpstan analyze -l 9 src Psalm Installation composer require --dev vimeo/psalm Configuration src/psalm.xml <?xml version="1.0"?> <psalm errorLevel="7" resolveFromConfigFile="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" findUnusedBaselineEntry="true" > <projectFiles> <directory name="src" /> <ignoreFiles> <directory name="vendor...

PHP SPL Exceptions Use Cases

An exception is used to immediately terminate the operation due to incorrect use of the code or incorrect data transferred for processing, or the inability to transfer data to another system. LogicException (and inherited) is thrown before the operation is executed, due to incorrect code usage. For example, an unknown function is called, a variable is passed with the wrong type, value, or wrong string length. RuntimeException (and inherited) is thrown during the execution of an operation, due to invalid data being passed or the inability to pass data to another system. For example, while processing the configuration file, it turned out that the value of the parameter was incorrect or the connection to the database was not established. Throwing LogicException and RuntimeException results in a HTTP 500 (Internal Server Error) server response because the error is on the server side. SPL Exceptions Class Tree LogicException BadFunctionCallException ...

How umask Function Works in PHP

Umask function subtracts permissions for files and directories on creation. Permission values: 0 = --- no permission 1 = --x execute 2 = -w- write 3 = -wx write and execute 4 = r-- read 5 = r-x read and execute 6 = rw- read and write 7 = rwx read, write and execute <?php // default 0644 = rw-r--r-- // we want 0400 = r-------- // 0777 - 0400 = 0377 umask(0377); // The file will be created with permissions 0400 fopen('test.txt', 'w');

Как настроить подключение к MS SQL через ODBC?

Image
В этой статье вы узнаете: Что такое ODBC; Как создать имя источника базы данных (DSN, Database Source Name); Как подключаться к ODBC из PHP. Настраивать будем под операционную систему Windows 7 с примерами кода на языке программирования PHP. Для тестирования подключения к MS SQL серверу я создал аккаунт на хостинге gearhost .