php artisan migrate , access denied - migrate

I get these errors when I migrate
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: YES) (SQL: select * from information_
schema.tables where table_schema = computersale and table_name = migrations)
and
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: YES)
my configurations:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'computersale'),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', 'root'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
and
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=computersale
DB_USERNAME=
DB_PASSWORD=root
I tried clearing the cache and config but didn't work.

Related

How to connect magento 2 to Redis

I have a magento 2 installation on docker, i would like to work with redis api, but not for magento2's session or page caching.
I would like to use the get() and set() commands to store strings, hash tables and many more.
Majorly what i need is a way to connect to a redis installed on docker instance that is on the same network as a magento 2 installation which is also on docker.
Thanks in advance.
I'm using Redis docker, maybe this will help you:
'session' => [
'save' => 'redis',
'redis' => [
'host' => 'redis',
'port' => '6379',
'password' => '',
'timeout' => '2.5',
'persistent_identifier' => '',
'database' => '0',
'compression_threshold' => '2048',
'compression_library' => 'gzip',
'log_level' => '1',
'max_concurrency' => '10',
'break_after_frontend' => '5',
'break_after_adminhtml' => '30',
'first_lifetime' => '600',
'bot_first_lifetime' => '60',
'bot_lifetime' => '7200',
'disable_locking' => '1',
'min_lifetime' => '60',
'max_lifetime' => '2592000'
]
],
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => 'redis',
'database' => '1',
'port' => '6379'
]
]
]
],
Regards

How configurate the certificate of php 5.6 in SmtpTransport of ZEND 2?

Using phpMailer the config is that (it is working):
$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => true,
'verify_depth' => 3,
'allow_self_signed' => true,
'peer_name' => 'smtp.rei.unicamp.br',
'cafile' => '/var/www/apache/conf/certs/cadeia-completa-globalsign.pem',
)
My old configuration of Smtp are (it is working in php versions before 5.6):
$options = new SmtpOptions(array(
'name' => $name,
'host' => $host,
'port' => 587,
'connection_class' => 'plain',
'connection_config' => array(
'username' => 'test',
'password' => 'test123',
'ssl' => 'tls',
),
Anyone knows how I put the first configuration on the SmtpOptions of Zend 2?
Thank you!!

Sendgrid Unauthenticated senders not allowed error php, zf2

I have integrate Sendgrid for my Zend Framework 2 Application using STMP API and i have used Zend Transport for but I get a error
"Caught exception: Cannot receive from specified address : Unauthenticated senders not allowed"
$request = $this->getRequest();
//$form = new Add();
// $product = new Product();
$username = 'XXX';
$password ='XXXX';
if ($request->isXmlHttpRequest()){ // If it's ajax call
$email = $request->getPost('email_add');
$message = $request->getPost('message');
try{
$message = new Message();
$message->addTo('jainudeenf007#gmail.com')
->addFrom('fawazj#digitalglare.com.au')
->setSubject('Greetings and Salutations!')
->setBody("Sorry, I'm going to be late today!");
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'sendgrid.com',
'host' => 'smtp.sendgrid.net',
'port' => 587, // Notice port change for TLS is 587
'connection_class' => 'smtp',
'connection_config' => array(
'auth' => 'login',
'username' => 'XXXXXX',
'password' => 'XXXXXX',
'ssl' => 'tls'
),
));
$transport->setOptions($options);
$transport->send($message);
exit;
}catch (\Exception $ex){
echo 'Caught exception: ', $ex->getMessage(), "\n";
exit;
}
}
Sendgrid has an api and this api is implemented by SlmMail (disclaimer: I am the author of SlmMail). Using that API is easier to use than using the old SMTP protocol.
I am not sure how to exactly configure the SMTP options, but previously we worked with the Google SMTP servers and it required this configuration:
'name' => 'gmail.com',
'host' => 'smtp.gmail.com',
'port' => 587,
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => $username,
'password' => $password,
),
This is slightly different than yours ("class" is "login", there is no "auth" option). Check also the documentation where all SMTP options are specified.
In addition to using the SimMail option, you can try using Zend's mail module as described in our documentation: http://sendgrid.com/docs/Integrate/Frameworks/zend.html
One other option is our Web API, for which we have a PHP library here: https://github.com/sendgrid/sendgrid-php
Try this
connection_class plain should work
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => $name,
'host' => $host,
'port' => 587,
'connection_class' => 'plain',
'connection_config' => array(
'username' => $username,
'password' => $password,
),
));
$transport->setOptions($options);
$transport->send($mail);

ActiveRecord::ConnectionNotEstablished error

I have written a rake task to update my database which I am doing by a model. I have called the function of model inside my rake task like this:
get_first_student = Student.get_first_id
I have written the model Student like following:
class Students < ActiveRecord::Base
attr_accessible :id, :roll_num :name, :class
self.table_name = 'students'
if Rails.env == "development"
CONN1 = establish_connection :adapter => "mysql2",
:database => "mydb_dev",
:username => "root",
:password => "" ,
:host => "localhost"
CONN2 = establish_connection :adapter => "mysql2",
:database => "mydb2_dev",
:username => "root",
:password => "",
:host => "1.2.3.4"
else
CONN1 = establish_connection :adapter => "mysql2",
:database => "mydb_prod",
:username => "root",
:password => "" ,
:host => "localhost"
CONN2 = establish_connection :adapter => "mysql2",
:database => "mydb2_prod",
:username => "root",
:password => "" ,
:host => "localhost"
end
def self.get_first_id
p "****"
p CONN1
p "****"
sql = %Q{SELECT MIN(id) FROM mydb.students;}
first_student_id = CONN1.connection.execute(sql).first[0]
return first_student_id
end
After running, I am getting this following output:
#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007f948c223120 #mon_owner=nil,
#mon_count=0, #mon_mutex=#<Mutex:0x007f948c2230d0>, #spec=#
<ActiveRecord::Base::ConnectionSpecification:0x007f948c2232d8 #config=
{:adapter=>"mysql2",:database=>"mydb_dev", :username=>"root", :password=>"",
:host=>"localhost"}, #adapter_method="mysql2_connection">, #reserved_connections={},
#queue=#<MonitorMixin::ConditionVariable:0x007f948c223080 #monitor=#
<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007f948c223120 ...>, #cond=#
<ConditionVariable:0x007f948c223058 #waiters=[], #waiters_mutex=#
<Mutex:0x007f948c223008>>>, #timeout=5, #size=5, #connections=[],
#automatic_reconnect=false>
ActiveRecord::ConnectionNotEstablished
In rails, there are two different adapter for mysql server one in mysql and mysql2 gem. Check if you have mysql gem in your gemfile. If not, then open rails console, and type ActiveRecord::Base.establish_connection("mysql://your_username:yourpassword#localhost/yourdatabasename"). Have you configured your mysql server. Are you getting error in all environments?. Check it by login into mysql server using command 'mysql -u USERNAME -p' by default its root and with not password.
Calling establish_connection the second time has disconnected the first pool you created and that's the CONN1 you're trying to use.
Although this method returns a ConnectionPool object that you can capture and use, it's worth avoiding. ActiveRecord manages the connection pools and unless you explicitly tell it differently will assume you only want one of them active. Recently they've added some nice new ways to manage multiple databases.

Local mysql settings in ZF2

I want add in my ZF2 application at begining of every mysql connection this mysql query/setting
SET time_zone = \'+00:00\';
for some reasons i couldn't do it on mysql conifiguration file.
So where i can do it?
(now i create dbadapter by config file:
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
etc...
)
Try this in your config file (for example in config/autoload/global.php)
return array(
'db' => array(
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET time_zone = \'+00:00\''
)
)

Resources