Laravel 4, Ubuntu, SQL Server 2008R2 - sql-server-2008-r2

I'm using default PHP 5.3.10 in my ubuntu box. and install php5-sysbase.
I tested with this code and success connected to my SQL Server
<?php
$link = mssql_connect('125.0.0.1', 'sa', '12345');
if(!$link) {
echo'Could not connect';
die('Could not connect: ' . mssql_error());
}
echo'Successful connection';
mssql_close($link);
Now I'm following the quickstart tutorial until arrive at database things in http://laravel.com/docs/quick#creating-a-migration
I use default db driver sqlsrv, with this config:
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => '125.0.0.1',
'database' => 'laravel',
'username' => 'sa',
'password' => '12345',
'prefix' => '',
),
When I execute php artisan migrate, I got an error
[Exception]
SQLSTATE[HY000]: General error: 102 General SQL Server error: Check message
s from the SQL Server [102] (severity 15) [(null)] (SQL: create table "migr
ations" ("migration" nvarchar(255) not null, "batch" int not null)) (Bindin
gs: array (
))
What could be the problem? Thanks for any helps
EDIT01:
here's sql message:
message_id language_id severity is_event_logged text
102 1033 15 0 Incorrect syntax near '%.*ls'.
here's my migration file:
<?php
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('email')->unique();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('users');
}
}

/vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Change this:
protected $wrapper = '"%s"';
To this:
protected $wrapper = '[%s]';

Related

Error while migrating in Laravel database on heroku

When running heroku run php artisan migrate I get this error, I want to host my app on heroku
In Connection.php line 712
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "price" cannot be cast automatically to type numeric
HINT: You might need to specify "USING price::numeric(15,2)". (SQL: ALTER TABLE purchases ALTER price TYPE NUMERIC
(15, 2))
In Connection.php line 501:
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "price" cannot be cast automatically to type numeric
HINT: You might need to specify "USING price::numeric(15,2)".
purchase table
lass ChangePurchasePriceDataTyp extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('purchases', function (Blueprint $table) {
$table->numeric('price',15,2)->unsigned()->default(0)->change();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('purchases', function (Blueprint $table) {
//
});
}
}
database.php
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => isset($DATABASE_URL['host']) ? $DATABASE_URL['host'] : null,
'port' => isset($DATABASE_URL['port']) ? $DATABASE_URL['port'] : null,
'database' => isset($DATABASE_URL['path']) ? ltrim($DATABASE_URL['path'], "/") : null,
'username' => isset($DATABASE_URL['user']) ? $DATABASE_URL['user'] : null,
'password' => isset($DATABASE_URL['pass']) ? $DATABASE_URL['pass'] : null,
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
what could be wrong? initial the datatype was decimal but I changed it to numeric

SoftDeletes Memory issue with php 7.4 and Illuminate 7.9.2

We have a project with eloquent (without Laravel).
Recently we upgrade to php 7.4, and then Iluminate/database to 7.9.2
In seeder, when we insert data into model without SofDelete, it works.
But when model have softdelete, it hangs.
Example Role:
use Illuminate\Database\Eloquent\Model as Eloquent;
class Role extends Eloquent {
protected $table = 'usuarios_roles';
public $timestamps = true;
...
$admin = Role::create(array(
'nombre' => 'Admin',
'vista' => '1',
'path' => '/admin/clientes/',
'editables' => 0
));
Works fine.
Example User:
require_once('EloquentRegAcc.php');
use Illuminate\Database\Eloquent\SoftDeletes;
class Usuario extends EloquentRegAcc
{
use SoftDeletes;
public $timestamps = true;
protected $dates = ['deleted_at'];
protected $table = 'usuarios';
...
$usuario_admin = Usuario::create(array(
'id_role' => $admin2->id,
'nombre' => 'Admin',
'email' => $email,
'password' => $password2,
'permissions' => '{}'
));
It give us an error:
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 20480 bytes) in /home/vagrant/code/project/vendor/illuminate/database/Eloquent/SoftDeletes.php on line 36
We try to upgrade Vagrant RAM, from 2GB to 4GB, and set ini_set('memory_limit', '4096M') , but no way.
In the database we have roles, but not users.
Same code with php 7.1 and Iluminate/database 5.x works fine.
not matter if is user or other table; if model have SoftDelete, hangs.
We have a "homemade" log in the app.
If we change
require_once('EloquentRegAcc.php');
use Illuminate\Database\Eloquent\SoftDeletes;
class Usuario extends EloquentRegAcc
{
To
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletes;
class Usuario extends Eloquent
{
Works as spect. We need to rewrite or log.

TYPO3 9.5 second database - Errors in ExtensionManager

I have a problem when adding a second third party Oracle database to the TYPO3 Configuration in a TYPO3 9.5. After adding the configuration I cannot install any extensions (including core extensions) in ExtensionManager anymore.
In LocalConfiguration.php I add a second database (it's the database of a patent management system - no "TYPO3 style"):
'DB' => [
'Connections' => [
'Default' => [
....
],
'MyDB' => [
'charset' => 'utf8',
'dbname' => 'xxx',
'driver' => 'oci8',
'host' => 'xxx',
'password' => 'xxx',
'port' => '1521',
'user' => 'xxx',
],
],
'TableMapping' => [
'SCHEMA.TABLE1' => 'MyDB'
],
'extTablesDefinitionScript' => 'extTables.php',
],
I use QueryBuilder in the action in my controller and I can query the table without any problems.
BUT installing any extension in ExtensionManager leads to the following error:
(1/1) TypeError
Argument 1 passed to TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener::getDatabaseType() must be of the type string, null given, called in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php on line 41
in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php line 93
*
* #param string $typeDefiniton
* #return string
*/
protected function getDatabaseType(string $typeDefiniton): string
{
$dbType = strtolower($typeDefiniton);
$dbType = strtok($dbType, '(), ');
at TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener->getDatabaseType(null)
in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php line 41
public function onSchemaColumnDefinition(SchemaColumnDefinitionEventArgs $event)
{
$tableColumn = $event->getTableColumn();
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
$dbType = $this->getDatabaseType($tableColumn['type']);
if ($dbType !== 'enum' && $dbType !== 'set') {
return;
}
at TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener->onSchemaColumnDefinition(object(Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs))
As soon as I remove the second database from LocalConfiguration.php the ExtensionManager is working again - but of course the QueryBuilder does not know the table any more :enttäuscht:

Yii2 and postgres connecttion

I tried yii2 and postgres database but when I try to query my table i got an error . How to fix this?
LINK for my error:
LINK for my database connection:
maybe you don't set defaultSchema on connection string
return [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;dbname=db_name',
'username' => 'db_username',
'password' => 'db_password',
'charset' => 'utf8',
'schemaMap' => [
'pgsql'=> [
'class'=>'yii\db\pgsql\Schema',
'defaultSchema' => 'public' //specify your schema here
]
], // PostgreSQL
];
see to here
OR
change your tableName() function in model like this
/**
* #inheritdoc
*/
public static function tableName()
{
return 'schemaName.table_name';
}

How to debug eloquent queries executed in Codeigniter

I'm using Eloquent 5.* on my CodeIgniter3.1.1 project, Everything works fine however i want to check the queries executed when a request is processed,
After some googling i came accross Using Eloquent ORM inside CodeIgniter with added Query Logging and having CI Profiler enabled i see "No Queries Executed",
my database.php configuration for Eloquent looks as below
//Eloquent ORM database connection
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'dsn' => 'mysql:host=localhost; dbname=communit_iwa_test charset=utf8;',
'host' => $db['default']['hostname'],
'database' => $db['default']['database'],
'username' => $db['default']['username'],
'password' => $db['default']['password'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => $db['default']['dbprefix'],
));
$capsule->setAsGlobal();
$capsule->bootEloquent();
$events = new Illuminate\Events\Dispatcher;
$events->listen('illuminate.query',function($query, $bindings, $time,$name) {
// Format binding data for sql insertion
foreach ($bindings as $i => $binding) {
if ($binding instanceof \DateTime) {
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
} else if (is_string($binding)) {
$bindings[$i] = "'$binding'";
}
}
// Insert bindings into query
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
// Add it into CodeIgniter
$db = & get_instance()->db;
$db->query_times[] = $time;
$db->queries[] = $query;
});
$capsule->setEventDispatcher($events);
/* End of file database.php */
/* Location: ./application/config/database.php */
Your Help is appreciated in advance
To view executed eloquent queries usegetQueryLog() method of the classIlluminate\Database\Capsule\Manager;
in short
Include Illuminate\Database\Capsule\Manager class in your controller or model as use Illuminate\Database\Capsule\Manager as Capsule;
use Capsule::getQueryLog() method to view an array of all queries executed in Eloquent ORM