The reason for working with migration is to create a table in mysql - laravel-5.8

php artisan migrate Error while executing
Illuminate\Database\Query Exception:SQL STATE[42000]: Syntax error or
access violation: 1253 COLLATION 'utf8_unicode_ci' is not valid for
CHARACTER SET 'utf8 8mb4' (SQL: select * from
information_schema.tables where table_schema = warehousing sing and
table_name = migrations)

You need to modify following changes,
Go to config > database.php
'connections' => [
....
'mysql' => [
......
'charset' => 'utf8mb4', // Update here : 'utf8'
'collation' => 'utf8mb4_unicode_ci', // Update here : utf8_unicode_ci

Related

Error ORA-12505: TNS:listener does not currently know of SID given in connect descriptor Laravel 5.8 Yajra

I get the following error Yajra\Pdo\Oci8\Exceptions\Oci8Exception ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
What I want is to be able to connect to Laravel 5.8.38 to Oracle (remote), and I'm not sure how to do the setup using the service name
Sql Developer Configuration
'connections' => [
'oracle' => [
'driver' => 'oracle',
'host' => '192.168.0.190',
'port' => '1521',
'database' => 'BDDESARR',
'service_name' => '???',
'username' => 'PAT_GUZ',
'password' => 'ujUYjjdk',
'charset' => '',
'prefix' => '',
],
Installation of Yajra following the step by step from https://github.com/yajra/laravel-oci8/tree/5.8
Terminal output
PS C:\wamp64\www\desarrollo\php\laravel\miproyect> composer require yajra/laravel-oci8:"5.8.*"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Writing lock file
Generating optimized autoload files
File config/database.php
'default' => env('DB_CONNECTION', 'oracle'),
'connections' => [
'oracle' => [
'driver' => 'oracle',
'host' => '192.168.0.190',
'port' => '1521',
'database' => 'BDDESARR',
'service_name' => '???',
'username' => 'PAT_GUZ',
'password' => 'ujUYjjdk',
'charset' => '',
'prefix' => '',
],
Additional information, I made the following code and it runs successfully
<?php
$conn = oci_connect('PAT_GUZ', 'ujUYjjdk', '192.168.0.190/BDDESARR');
if (!$conn) {
$e = oci_error();
var_dump($e);
}
$stid = oci_parse($conn, 'SELECT * FROM MY_TABLE');
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
Laravel 5.8.38
PHP 7.3.12
Oracle: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 -
64bit Production
Windows 10 64 bit
Wamp64
I don't know anything about Laravel, Yajra and other things you mentioned, but this:
'database' => 'BDDESARR',
'service_name' => '???',
looks if not wrong then suspicious. SQL Developer connection suggests that Service name = 'bddesarr'. I don't know what "database" is supposed to be. SID, perhaps, as Oracle complains that SID isn't right.

invalid value for parameter "client_encoding": "utf8mb4" (SQL: select * from "tablename") when deploy laravel to heroku [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am trying to deploy my laravel app to heroku but it returns an error:
SQLSTATE[22023]: Invalid parameter value: 7 ERROR: invalid value for parameter "client_encoding": "utf8mb4" (SQL: select * from "tablename").
I changed my tablename collation and columns from utf8mb4_unicode_ci to utf8unicode_ci but nothing happened. Please help me. I tried all the possible solutions I've searched but nothing really works.
I have faced the same problem. Mistakenly i have not added DB_CONNECTION=pgsql in config vars on Heroku dashboard. Inside setting tab click on Reveal Config Vars and add DB_CONNECTION=pgsql there.
Another way just simply add config vars using terminal.
heroku config:add DB_CONNECTION=pgsql
After setting up your psql details as specified up there on config/database.php
run
git push origin master
git push heroku master
And try run the bash again..
heroku run bash
php artisan migrate:fresh
yes
and you're good to go
Laravel Databse Connection Environment issue
You are probably using the Postgresql as the Database instead of MySql.
Then please configure the database config in config/database.php file
'default' => env('DB_CONNECTION', 'pgsql')
or set the DB_CONNECTION in .env as pgsql
pgsql will not support utf8mb4, it is for the MySQL, if you are using Postgresql pls correct the connection environment.
For mysql:
[
'database.connections.rds' => [
'driver' => 'mysql',
'host' => $endpoint,
'port' => $port,
'database' => $db_name,
'username' => $user,
'password' => $password,
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
]
]
for Postgres
[
'database.connections.rds' => [
'driver' => 'pgsql',
'host' => $endpoint,
'port' => $port,
'database' => $db_name,
'username' => $user,
'password' => $password,
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
]
]
Are you using laravel/telescope?
I had the same problem when trying to implement my project. To resolve the error, I removed laravel/telescope from my project.
'mysql' => [
// ...
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
// ...
],
This happens at the environment variable configuration level on Heroku if you haven't done key = DB_CONNECTION and value = pgsql.
In config/database.php, Use default connection
'default' => 'pgsql',
"client_encoding": "utf8"
If you are using MySQL than change default connection to
'default' => 'mysql',
"client_encoding": "utf8mb4"

How to use Athena with Laravel?

We're looking to have a specific search/aggregate/graphs page use AWS Athena instead of Postgres.
We've tried 2 ODBC packages for laravel, and discovered that Laravel uses prepared statements and Athena's Simba ODBC driver does not support prepared statements. PDO supports emulating prepared statements, which sounds like exactly what would work, but enabling ATTR_EMULATE_PREPARES doesn't make any difference.
This is the error we're getting:
Illuminate/Database/QueryException with message 'SQLSTATE[42000]: Syntax error or access violation: 0 [Simba][Athena] (1040) An error has been thrown from the AWS Athena client. Athena Error No: 102, HTTP Response Code: 1, Error Message: SYNTAX_ERROR: line 1:1: Incorrect number of parameters: expected 1 but found 0 [Execution ID: ] (SQLPrepare[0] at /build/php7.2-PL0pac/php7.2-7.2.16/ext/pdo_odbc/odbc_driver.c:206) (SQL: select * from "qa_lines_csv" where "id" > 100 limit 1)'
Our database config:
'test_athena' => [
'driver' => 'odbc',
'dsn' => 'odbc:Driver=/opt/simba/athenaodbc/lib/64/libathenaodbc_sb64.so;'
.'AwsRegion=us-east-1;'
.'AuthenticationType=IAM Credentials;'
.'UID=<redacted>;'
.'PWD=<redacted>;'
.'S3OutputLocation=s3://<redacted>/;',
'host' => env('ATHENA_HOST', 'localhost'),
'port' => env('ATHENA_PORT', '5432'),
'database' => env('ATHENA_DATABASE', 'forge'),
'username' => env('ATHENA_USERNAME', 'forge'),
'password' => env('ATHENA_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'options' => [
\PDO::ATTR_EMULATE_PREPARES => true,
],
$pdo = DB::connection('test_athena')->getPdo();
// this crashes
$pdo->prepare('select * from "qa_lines_csv" where "id" > ? limit 1')->execute([100]);
// this does not crash
$pdo->prepare('select * from "qa_lines_csv" where "id" > 100 limit 1')->execute([]);
// this crashes
DB::connection('test_athena')->table('qa_lines_csv')->where('id', '>', 100)->first()
It seems like there is a bug between PDO and the Simba driver, one of them is not allowing the PDO emulation to work. Athena should just start supporting prepared statements.
We've already written our application, so we can't re-write everything to not use Laravel's query builder and manually concatenate strings into queries.

Database [] not configured Laravel 5

I create new db in phpmyadmin and new tables.
Then i do
public function next(Request $request){
$langs = DB::connection('mydb')->select('select * from lang');
}
and get
Database [compgen] not configured.
in my .env
DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=123
in my config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', '123'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'test_',
'strict' => false,
],
In my case I used 2 db connections and the second added was not cached, the command call:
php artisan config:cache
did the trick.
To see what's going on it was sufficient to output the $connections variable in DatabaseManager->configure method.
You're using single connection, so you don't need to specify it:
$langs = DB::table('lang')->get();
You should use connection() method only when you're working with multiple DB connections.
For me the connection worked in development but not in the production environment, so after a lot of searching, I had to rebuild the configuration cache and It has worked. I ran the following command in the laravel root directory:
php artisan config:cache
Anyone stumbling upon this - if you are using Laravel 5.4 or newer, you can setup a new database connection in config/database.php
'mysql_test' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE_TEST', 'forge'),
'username' => env('DB_USERNAME_TEST', 'forge'),
'password' => env('DB_PASSWORD_TEST', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_AUTO_CREATE_USER',
'NO_ENGINE_SUBSTITUTION',
],
'engine' => null,
],
I created 3 new env variables DB_USERNAME_TEST, DB_PASSWORD_TEST, DB_DATABASE_TEST
Edit .env with something like
DB_DATABASE_TEST=test_db
DB_USERNAME_TEST=local
DB_PASSWORD_TEST=localpassword
Make sure config is refreshed: php artisan config:cache
You should be able to run a database migrate on your new test database, like so:
php artisan migrate:refresh --database=mysql_test
In my case it was a bad database username. I had it set in my config/database.php as well as the .env file and one of them was different than the other. Found this thread when searching, thought this might help someone.
I struggled with this error for a few hours and found out solution that works for me. If you can not delete cache with php artisan config:cache because it throws error after you run it:
[InvalidArgumentException]
Database [] not configured
And if you are sure that your connections parameters are good then try manually delete bootstrap cache config files which are placed in app/bootstrap/cache folder.
Hope it helps someone.
make sure the parameters
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=dbuser
DB_PASSWORD="password"
and then issue,
php artisan optimize:clear
I had the same issue but when i added
'default' => env('DB_CONNECTION', 'mysql'),
to database.php.It seems to have solved the problem
if this error shows when you use the validation so it is simple :) just check all the validation rules and messages are written >
correctly
for me i faced this error and i solve it by replace only point by comma in the validation rules.

Laravel: SQLSTATE[28000] [1045] Access denied for user 'homestead'#'localhost'

I just installed laravel and made a migration. But when i try to run it i get this error:
[PDOException]
SQLSTATE[28000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Can anyone tell me what is wrong? I think the Database.php file looks different than normal. Is this something new in the new Laravel?
My Database config:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'LaraBlog'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Hope someone can help me :)
I tried to make changes to database.php file present within config folder it looks something like this
'default' => 'mysql',
....
...
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'sample'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
I am not using any VM, I am using my local machine, with the database user as root and password a null.
I have also changed my .env file and it looks something like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=zLzPMzs5W4FNNuguTmbG8M0iFqhIVnsP
DB_HOST=localhost
DB_DATABASE=sample
DB_USERNAME=root
DB_PASSWORD=null
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
Even after doing all the changes when I try to register using the registration form that is shipped with laravel, I try to add a user to my database I get the following error
After doing all the changes I cleared the cache and loaded it again and it seems to work for me now!
if any one is also facing the same issue just run the following commands
php artisan cache:clear
php artisan config:cache
I figured it out :) Had to chance the .env file :)
Is there any changes in the schemaes?
Shouldn't this work:
public function up()
{
// Create table with columns
Schema::create('users', function($table) {
$table->increments('id');
$table->string('username');
$table->string(Hash::make('password'));
$table->string('firstname');
$table->string('lastname');
$table->string('email')
$table->string('role');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
// Insert table to database
Schema::drop('users');
}
Try to check out the ".env" file in your root directory. These values are taken first. Yours are just the defaults if there are none given in the .env file.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Your_Database_Name
DB_USERNAME=Your_UserName
DB_PASSWORD=Your_Password
Make changes in the database.php file in **config > local >database.php
rather than change config > database.php file.
hope it will work ;)
practically when you are using localhost server like xampp, you create the database manually "homestead", such errors are due to missing database arguments. 100% percent working test it and see
hit your cmd and type in:
create database homestead;
i got the same issue after creating laravel project. The authentication command run successfully.
php artisan make:auth
But when i try to register or login i got the same error. I run the following command
php artisan config:clear
then stopped laravel application and also my server. after restarting my laravel app and server everything was ok.
Tried all the solutions here but no work for me
This Worked on the first try:
If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values.
I found this solution from here laravel.io (Read the solution of Byjml)

Resources