how to fix my wordpress server connection issue using xampp - database

learning to use xampp for localhosting wordpress, at the end of tutorial where you enter info database, username, pass etc
cant get a connection, i assume it has to do with username,database and password credentials.
ive tried changing everything in wp-config-sample, and even checked out setup-config which didnt seem as other tutorials described, alot more code.
Im trying to understand that i am entering everything correctly, i believe at one point i put my phpmyadmin server on port 3307. down below is a picture of the form page in browser and code from config-sample, setup-config is pretty big, i will add if it is suggested
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the web site, you can copy this file to "wp-config.php"
* and fill in the values.
*
* This file contains the following configurations:
*
* * Database settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* #link https://wordpress.org/support/article/editing-wp-config-php/
*
* #package WordPress
*/
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordtests' );
/** Database username */
define( 'DB_USER', 'root' );
/** Database password */
define( 'DB_PASSWORD', '' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
/**##+
* Authentication unique keys and salts.
*
* Change these to different unique phrases! You can generate these using
* the {#link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
*
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
*
* #since 2.6.0
*/
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
/**##-*/
/**
* WordPress database table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* #link https://wordpress.org/support/article/debugging-in-wordpress/
*/
define( 'WP_DEBUG', false );
/* Add any custom values between this line and the "stop editing" line. */
/* That's all, stop editing! Happy publishing. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Related

Add column to all tables through migration in Laravel

As our project scaled we decided that every single data should belong to companies that created them. Therefore I'm to add a column "data_owner_company_id" that points to the company that owns given record. Yes it's possible to generate migration to add this column to each model but that is not really feasible since there is 120+ tables & models. How can i tackle this with minimum effort ?
For the model part i figured i can easily apply it to all models by inheritance, but not sure about migration.
TL;DR
How to add int column to all tables by migration ?
Database: MySQL v8
Framework: Laravel 8, PHP 7.3
It's simple if you find all the tables' names in your database, you have to loop and create columns for each and every table.
Try creating columns using queues as it will be a heavy job for 120 tables.
Check the following code:
class CreateDataOwnerCompanyIdtoEachTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up ()
{
$columns = 'Tables_in_' . env('DB_DATABASE');//This is just to read the object by its key, DB_DATABASE is database name.
$tables = DB::select('SHOW TABLES');
foreach ( $tables as $table ) {
//todo add it to laravel jobs, process it will queue as it will take time.
Schema::table($table->$columns, function (Blueprint $table) {
$table->unsignedInteger('data_owner_company_id');
});
}
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down ()
{
$columns = 'Tables_in_' . env('DB_DATABASE');//This is just to read the object by its key, DB_DATABASE is database name.
$tables = DB::select('SHOW TABLES');
foreach ( $tables as $table ) {
//todo add it to laravel jobs, process it will queue as it will take time.
Schema::table($table->$columns, function (Blueprint $table) {
$table->dropColumn('data_owner_company_id');
});
}
}
}
I'm not 100% sure that it's going to work, but here it goes:
Create class that extends Illuminate\Database\Schema\Blueprint;
In constructor call parent construntor and then
$this->unsignedBigInteger('data_owner_company_id')->nullable();
Use your new class in migrations instead of default Blueprint

Symfony Integrity constraint violation

I tried cascade remove on the 'file' entity that keeps my 'expanse' entity from removing. But this doesn't work.
The error:
Cannot delete or update a parent row: a foreign key constraint fails (zioo.files, CONSTRAINT FK_6354059F395DB7B FOREIGN KEY (expense_id) REFERENCES expenses (id))
The file entity code:
/**
* #ORM\ManyToOne(targetEntity="Expense", inversedBy="files", cascade={"remove"})
* #ORM\JoinColumn(name="expense_id", referencedColumnName="id")
*/
private $expense;
The expanse entity code:
/**
* #ORM\OneToOne(targetEntity="File", cascade={"persist"})
* #ORM\JoinColumn(name="file_id", referencedColumnName="id")
*/
private $file = null;
/**
* #ORM\OneToMany(targetEntity="File", mappedBy="expense", cascade={"remove"})
*/
protected $files;
If a expanse gets deleted the file associated with it should be deleted too.
Using cascade={"remove"} the entity won't be deleted if it is owned by something else. The issue seems to be caused by doctrine, as the expanse entity has 2 relations to file entity and this causes doctrine to "think" that your file entity is owned by something else and not send a delete to database for it, before trying to delete the expanse.
As a result when it tries to delete the expanse this error is thrown.
To test it, remove private $file = null;relation and will see that it will work.
To overcome this, I suggest to use onDelete="CASCADE" on the owning side:
/**
* #ORM\ManyToOne(targetEntity="Expense", inversedBy="files", cascade={"remove"})
* #ORM\JoinColumn(name="expense_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $expense;
In this case, you no longer need cascade={"remove"}:
/**
* #ORM\OneToMany(targetEntity="File", mappedBy="expense")
*/
protected $files;
Doctrine delete relation options

How to programmatically change table prefix in symfony2-doctrine

I setup my symfony3 application to use 2 different databases. they are pretty much similar, structure of tables are the same and so the fields. The problem is, for example, the article table in db1 is called db1_article and article table in db2 is called db2_article. They have different data but same structure.
Now, I am setting up an entity for articles like that:
/**
* #ORM\Entity
* #ORM\Table(name="db1_article")
*/
class Article {
...
}
I'd prefer not to create a different entity for the same table in db2, can I dinamically define the table name somewhere in order to avoid duplications?
thanks
In order to change the table you've got to to update Doctrine's class meta data of that entity.
// getEntityManager() = $this->getDoctrine()->getManager()
$articleMetaData = $this->getEntityManager()->getMetadataFactory()->getMetadataFor(Article::class);
$metaDataBuilder = new ClassMetadataBuilder($articleMetaData);
$metaDataBuilder->setTable('db2_article');
$this->getEntityManager()->getMetadataFactory()
->setMetadataFor(Article::class, $metaDataBuilder->getClassMetadata());
$article2MetaData = $this->getEntityManager()->getClassMetadata(Article::class);
$article2MetaData->getTableName(); // is now db2_article
$this->getEntityManager()->find(Article::class, 1); // will query db2_article ID -> 1
To see what the class meta data is up to as in methods, see: Doctrine PHP Mapping
I would go for an approach using different entity managers for each database, so you can use the same entities.
//config.yml
doctrine:
dbal:
default_connection: first_entity_manager
connections:
first_entity_manager:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
second_entity_manager:
driver: %database_2nd_driver%
host: %database_2nd_host%
port: %database_2nd_port%
dbname: %database_2nd_name%
user: %database_2nd_user%
password: %database_2nd_password%
charset: UTF8
orm:
default_entity_manager: first_entity_manager
entity_managers:
first_entity_manager:
connection: first_entity_manager
mappings:
AppBundle: ~
second_entity_manager:
connection: second_entity_manager
mappings:
AppBundle: ~
Then just program some functions to use the correct entity manager
$em_first = $this->getDoctrine()->getManager('first_entity_manager');
$em_second = $this->getDoctrine()->getManager('second_entity_manager');
$article_first_em = $em_first->getRepository('AppBundle:Article')->find(1);
$article_second_em = $em_second->getRepository('AppBundle:Article')->find(2);
For the table prefix I would use a table suscriber
Quite old but still works
How to setup table prefix in symfony2
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/sql-table-prefixes.html

database configuration error - though I've set the settings and added the file

If you were to browse to my website you would see I have database connection issues. I get CakePHP's error message telling me the file is missing. I've checked several times and everything I'm using cakePHP3. I must have screwed up sonewhere, but I don't want to start all over again If you were to look at my code:
<?php
/**
* This is core configuration file.
*
* Use it to configure core behaviour of CakePHP.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* #copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* #link http://cakephp.org CakePHP(tm) Project
* #package app.Config
* #since CakePHP(tm) v 0.2.9
* #license http://www.opensource.org/licenses/mit-license.php MIT License
*
* Database configuration class.
* You can specify multiple configurations for production, development and testing.
*
* datasource => The name of a supported datasource; valid options are as follows:
* Database/Mysql - MySQL 4 & 5,
* Database/Sqlite - SQLite (PHP5 only),
* Database/Postgres - PostgreSQL 7 and higher,
* Database/Sqlserver - Microsoft SQL Server 2005 and higher
*
* You can add custom database datasources (or override existing datasources) by adding the
* appropriate file to app/Model/Datasource/Database. Datasources should be named 'MyDatasource.php',
*
*
* persistent => true / false
* Determines whether or not the database should use a persistent connection
*
* host =>
* the host you connect to the database. To add a socket or port number, use 'port' => #
*
* prefix =>
* Uses the given prefix for all the tables in this database. This setting can be overridden
* on a per-table basis with the Model::$tablePrefix property.
*
* schema =>
* For Postgres/Sqlserver specifies which schema you would like to use the tables in. Postgres defaults to 'public'. For Sqlserver, it defaults to empty and use
* the connected user's default schema (typically 'dbo').
*
* encoding =>
* For MySQL, Postgres specifies the character encoding to use when connecting to the
* database. Uses database default not specified.
*
* unix_socket =>
* For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port`
*
* settings =>
* Array of key/value pairs, on connection it executes SET statements for each pair
* For MySQL : http://dev.mysql.com/doc/refman/5.6/en/set-statement.html
* For Postgres : http://www.postgresql.org/docs/9.2/static/sql-set.html
* For Sql Server : http://msdn.microsoft.com/en-us/library/ms190356.aspx
*/
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'username',
'password' => 'password', // db credentials removed
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
public $test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'test_database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
}
I don't know why Cake is not recognizing my file. I have the file placed properly in the directory it should be in. I remember trying to make the app work on shared hosting and that is how my Cake 2 thing might have been introduced. I'm stuck, guys.

cakePHP "session" is not returning session ID

I am into development of a cakePHP based web application.
Here are my core.php settings for session handling
Configure::write('Session.save', 'database');
/**
* The name of the table used to store CakePHP database sessions.
*
* 'Session.save' must be set to 'database' in order to utilize this constant.
*
* The table name set here should *not* include any table prefix defined elsewhere.
*/
Configure::write('Session.table', 'cake_sessions');
/**
* The DATABASE_CONFIG::$var to use for database session handling.
*
* 'Session.save' must be set to 'database' in order to utilize this constant.
*/
//Configure::write('Session.database', 'default');
Configure::write('Session.start', true);
/**
* The name of CakePHP's session cookie.
*/
Configure::write('Session.cookie', 'CAKEPHP');
/**
* Session time out time (in seconds).
* Actual value depends on 'Security.level' setting.
*/
Configure::write('Session.timeout', '300');
/**
* If set to false, sessions are not automatically started.
*/
Configure::write('Session.start', true);
/**
* When set to false, HTTP_USER_AGENT will not be checked
* in the session
*/
Configure::write('Session.checkAgent', true);
/**
* The level of CakePHP security. The session timeout time defined
* in 'Session.timeout' is multiplied according to the settings here.
* Valid values:
*
* 'high' Session timeout in 'Session.timeout' x 10
* 'medium' Session timeout in 'Session.timeout' x 100
* 'low' Session timeout in 'Session.timeout' x 300
*
* CakePHP session IDs are also regenerated between requests if
* 'Security.level' is set to 'high'.
CakePHP session id is always blank. although other session read/write activities are working perfectly fine.
Below is the session object.
SessionComponent Object
(
[__active] => 1
[__started] =>
[__bare] => 0
[valid] =>
[error] => Array
(
[2] => Auth.redirect doesn't exist
)
[_userAgent] => 2abebfb51fc971ec64569f7cd415fe0b
[path] => /
[lastError] => 2
[security] => high
[time] => 1278950154
[sessionTime] => 1278953154
[watchKeys] => Array
(
)
[id] =>
[_log] =>
[host] =>localhost
[enabled] => 1
[cookieLifeTime] => 0
)
All the other session variable are stored and retrieved properly, the problem is I am not getting session id at any stage.
Can you please help me what can be problem.
Thanks,
Sourabh
use session_id()
I hope it will work for you.
I had such experience and it's not good at all. Check if any of the resources are missing. I.e. some images, css or js files could be missing and then Cake loads the missing controller/action page which could reset the session.
refer to cakephp session id Empty
try to start the session with
$this->Session->start();

Resources