Create new data base phalcon php - phalcon

I need to create a new database in the Phlacon PHP.
Ex.: Create schema TEST001;
In my micro application I need to generate new databases. But the default Phalcon database is already set to COMPANY
How can I do on Phalcon PHP?

I think the easiest way would be to use raw query directly in controoler's action.
Please refer to How to run RAW SQL query in PhalconPHP

I created a new connection in services:
$di->setShared('db_teste', function () {
$config = $this->getConfig();
$class = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
$connection = new $class([
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'charset' => $config->database->charset
]);
return $connection;
});
And in the method I did so:
$this->getDi()->getShared('db_teste')->query("CREATE DATABASE COMPANY");
Thank you #klay

Related

How to use Wasabi (AmazonS3) in sabre/dav?

I am building a WebDAV server using sabre/dav, I want to create a WebDAV server file storage location in Wasabi which is compatible with AmazonS3, I did some research and found something that looks like AWS.php but I don't know how to use it. If anyone knows how to do this specifically, please respond.
What we tried:
・Download s3dav (https://github.com/audionamix/s3dav) and install the file.
・Server.php was written as follows
<?php
use Sabre\DAV;
use Aws\S3\S3Client;
// The autoloader
require 'vendor/autoload.php';
$raw_credentials = array(
'credentials' => array(
'key' => '<insert-access-key>',
'secret' => '<insert-secret-key>'
),
//'profile' => 'wasabi',
'endpoint' => 'https://s3.wasabisys.com',
'region' => 'us-east-1',
'version' => 'latest',
'use_path_style_endpoint' => true,
'use_path_style' => true,
'use_ssl' => true,
'port' => 443,
'hostname' => 's3.wasabisys.com',
'bucket' => '<bucket-name>',
);
// establish an S3 Client.
$s3 = S3Client::factory($raw_credentials);
// Now we're creating a whole bunch of objects
//$rootDirectory = new DAV\FS\Directory('public');
$rootDirectory = new DAV\FS\S3Directory("/",'<bucket-name>',$s3);
// The server object is responsible for making sense out of the WebDAV protocol
$server = new DAV\Server($rootDirectory);
// If your server is not on your webroot, make sure the following line has the
// correct information
$server->setBaseUri('/server.php/');
// The lock manager is reponsible for making sure users don't overwrite
// each others changes.
$lockBackend = new DAV\Locks\Backend\File('data/locks');
$lockPlugin = new DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
// This ensures that we get a pretty index in the browser, but it is
// optional.
$server->addPlugin(new DAV\Browser\Plugin());
// All we need to do now, is to fire up the server
$server->exec();
Result:
The file name list is displayed, but it is displayed as 0 bytes.
Uploading is working, but other operations are not working (file size is correct on Wasabi).
”4.4.0 Exception Cannot traverse an already closed generator" is displayed.

Web push notification example with PHP backend

I am looking for an example for web push notification with JS code and PHP backend. Can anyone share example code or a tutorial?
Here's a basic example that uses web-push-php : https://github.com/Minishlink/web-push-php-example
Main PHP code is:
<?php
require __DIR__ . '/vendor/autoload.php';
use Minishlink\WebPush\WebPush;
$auth = array(
'VAPID' => array(
'subject' => 'https://github.com/Minishlink/web-push-php-example/',
'publicKey' => 'BCmti7ScwxxVAlB7WAyxoOXtV7J8vVCXwEDIFXjKvD-ma-yJx_eHJLdADyyzzTKRGb395bSAtxlh4wuDycO3Ih4',
'privateKey' => 'HJweeF64L35gw5YLECa-K7hwp3LLfcKtpdRNK8C_fPQ', // in the real world, this would be in a secret file
),
);
$webPush = new WebPush($auth);
$res = $webPush->sendNotification(
$subscription['endpoint'],
"Hello!", // payload
$subscription['key'],
$subscription['token'],
true // flush
);
// handle eventual errors here, and remove the subscription from your server if it is expired
Hope this helps :)

Yii - How to implement curly brackets in your module/models?

I must be missing something here, because I have the following in my config/main.php:
'db'=>array(
...some config...
'tablePrefix' => 'appname_'
...more config...
),
Then I created a new module (testModule) and have listed the table name there as 'test_user':
public $userTable = '{{test_user}}';
In my DB migration script I create the mysql table like so:
$this->createTable(Yii::app()->getModule('test')->userTable, array(
"id" => "pk",
"username" => "varchar(20) NOT NULL",
"password" => "varchar(128) NOT NULL",
"email" => "varchar(128) NOT NULL",
"active" => "varchar(128) NOT NULL",
"created" => "int(10) NOT NULL",
"updated" => "int(10) NOT NULL",
));
BUT, when I run the migration script, the table name in the DB is {{test_user}}, when what I expected was 'appname_test_user'.
What am I doing wrong here?
Check your console config file. You should have there the same 'tablePrefix' in 'db' section as in main.php (or where you store configuration of web app db). Running migrations, you execute yiic and console application config is used.
To avoid that confusion in future, you can move all settings of db component into another config file (ex config/db.php). Then you can include it in both config/console.php and config/main.php this way:
//..
'db'=>require('db.php'),
//..

How to configure SQLite in Kohana 3?

I'm struggling to find any information on how to configure SQLite in Kohana 3.2. I mainly need to know:
What should I set hostname, database, username and password to (with default user and no password)?
Also, how can I set the path to the SQLite database file?
What should the "type" be? I tried "sqlite" but I get an error Class 'Database_Sqlite' not found.
This is my current configuration options:
'exportedDatabase' => array
(
'type' => 'sqlite',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => $hostname,
'database' => $database,
'username' => $username,
'password' => $password,
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
You can use PDO through Database module. The proper way of configuring it looks like this:
'exportedDatabase' => array(
'type' => 'pdo',
'connection' => array(
'dsn' => 'sqlite:/path/to/file.sqlite',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => NULL, /* IMPORTANT- charset 'utf8' breaks sqlite(?) */
'caching' => FALSE,
'profiling' => TRUE,
),
One disadvantage of using PDO in Kohana is that in ORM you have to specify all fields by hand in your model (you should do it anyway for performance reasons) because of how different database systems handle listing of table fields.
There is also real database module created by banditron. You have to remember that's it is NOT a drop-in replacement for Database module and therefore Kohana's ORM will not work with it. Other than that it's pretty neat and has wide support for database systems other than SQLite.
As I found out, Kohana 3.x doesn't actually support SQLite. There's an unsupported module for it and, as far as I can tell, it's not working.
It's easy enough to use PDO though and the syntax is pretty much the same as Kohana's ORM:
$db = new PDO('sqlite:' . $dbFilePath);
$query = $db->prepare('CREATE TABLE example (id INTEGER PRIMARY KEY, something TEXT)');
$query->execute();
$query = $db->prepare("INSERT INTO example (id, something) VALUES (:id, :something)");
$query->bindParam(':id', $id);
$query->bindParam(':something', $something);
$query->execute();
I don't use Kohana, but this should work:
'hostname' => /path/to/your/sql/lite/file.sqlite
'database' => ''
'username' => ''
'password' => ''

Use joomla user table with cakephp

i have working joomla project (domain.kz).
and i need to build new independent project on subdomain (newapp.domain.kz)
but i want to use joomla user table. (to let user auth with joomla logins)
can i declare in user model the joomla jos_users fields
is it possible to use 2 DB (old one for auth, the new one for new app)
Create a new database config in app/config/database.php, then create your model as normal:
var $joomla_connection = array('driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'password!',
'database' => 'joomla_db',
'prefix' => 'jos_'); // I think this is correct
class User extends AppModel {
var $name = 'User';
var $useDbConfig = 'joomla_connection';
//your code here
//....
}
you will might experience problems with Auth when you login with the "security_salt" and "cipher" from cake against the user login data, that are created through joomla.
if Joomla saves md5 encrypted passwords you can modify cakestandard encryption with this:
change hash function - cake cookbook