<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DB | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/category/db/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Fri, 17 Jan 2025 16:34:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Doctrine: WHERE IN with array of integers</title>
		<link>https://nerdpress.org/2025/01/17/doctrine-where-in-with-array-of-integers/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 17 Jan 2025 16:34:32 +0000</pubDate>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Sql]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3381</guid>

					<description><![CDATA[<p>Since I stumbled across this the other day, here&#8217;s how you build an SQL query with a WHERE IN condition for an array of integers. This is surprisingly not intuitive, as you cannot simply pass an array of integers to a prepared statement. Instead, you need to add special binding types to inform Doctrine that &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2025/01/17/doctrine-where-in-with-array-of-integers/" class="more-link">Continue reading<span class="screen-reader-text"> "Doctrine: WHERE IN with array of integers"</span></a></p>
The post <a href="https://nerdpress.org/2025/01/17/doctrine-where-in-with-array-of-integers/">Doctrine: WHERE IN with array of integers</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Since I stumbled across this the other day, here&#8217;s how you build an SQL query with a <code>WHERE IN</code> condition for an array of integers.</p>



<p>This is surprisingly not intuitive, as you cannot simply pass an array of integers to a prepared statement. Instead, you need to add special binding types to inform Doctrine that this is indeed an array of integers.</p>



<p>It&#8217;s very well explained in the documentation under the Parameters Conversion section:<br /><a href="https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/data-retrieval-and-manipulation.html#list-of-parameters-conversion">https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/data-retrieval-and-manipulation.html#list-of-parameters-conversion</a><br />But it is rather hard to find and it took me a while.</p>



<p>The trick is to add the array binding types to the the types parameters to the query method. In the case of integers, it is<code> \Doctrine\DBAL\ArrayParameterType::INTEGER</code>. <br />Now Doctrine knows how to handle the types in the array while binding the values.</p>



<span id="more-3381"></span>



<p>Example:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">$sql = <span class="hljs-string">'SELECT * FROM items WHERE id IN (?)'</span>; 
$numbersAsStrings = <span class="hljs-string">"1,2,3"</span>;
$numbers = array_map(<span class="hljs-string">'intval'</span>, explode(<span class="hljs-string">','</span>, $numbersAsStrings));
$users = $con-&gt;fetchAllAssociative(
  $sql, 
  &#91;$numbers], 
  &#91;ArrayParameterType::INTEGER]
);</code></span></pre>


<p>If you omit the types, Doctrine will simply try to bind the array as string, which will fail and you get this error:<br /><em>Array to string conversion</em></p>



<p>If you try to pass it as a comma-separated string yourself and omit the types like <kbd><code>$numbers = implode(',',array_map('intval', explode(',', $numbersAsStrings)));</code></kbd> You will get an error because Doctrine expects an array of values for the <kbd>IN</kbd> clause and not a string.<br />Error: <br /><em>count(): Argument #1 ($value) must be of type Countable|array, string given</em></p>



<p>I hope this helps someone finding out how to make <kbd>WHERE IN</kbd> SQL queries with Doctrine more quickly than me next time.</p>



<p></p>The post <a href="https://nerdpress.org/2025/01/17/doctrine-where-in-with-array-of-integers/">Doctrine: WHERE IN with array of integers</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Invalid table or database name mysql.sock</title>
		<link>https://nerdpress.org/2024/09/13/invalid-table-or-database-name-mysql-sock/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 13 Sep 2024 17:55:12 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3333</guid>

					<description><![CDATA[<p>In a development Docker setup, I needed to upgrade the MySQL database from version 5.6 to version 8. The data was stored as a Docker volume in a data directory. After the update, I encountered the following error: my_db.mysql &#124; 2024-08-16T09:40:21.463770Z 2 [ERROR] [MY-010520] [Server] Invalid (old?) table or database name 'mysql.sock'my_db.mysql &#124; 2024-08-16T09:40:21.468287Z 2 &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2024/09/13/invalid-table-or-database-name-mysql-sock/" class="more-link">Continue reading<span class="screen-reader-text"> "Invalid table or database name mysql.sock"</span></a></p>
The post <a href="https://nerdpress.org/2024/09/13/invalid-table-or-database-name-mysql-sock/">Invalid table or database name mysql.sock</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p><br />In a development Docker setup, I needed to upgrade the MySQL database from version 5.6 to version 8. The data was stored as a Docker volume in a data directory. After the update, I encountered the following error:</p>



<pre class="wp-block-preformatted">my_db.mysql      | 2024-08-16T09:40:21.463770Z 2 [ERROR] [MY-010520] [Server] Invalid (old?) table or database name 'mysql.sock'<br />my_db.mysql      | 2024-08-16T09:40:21.468287Z 2 [ERROR] [MY-010784] [Server] Failed to open dir /var/lib/mysql/mysql.sock</pre>



<p>Apparently, MySQL 8 treats every file or directory in the data directory as a database table, whereas in the previous version, MySQL 5, only directories were recognized as database tables.</p>



<p>As the the c<a href="https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-0.html" target="_blank" rel="noopener" title="">hangelog</a> of MySql 8 states:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Because the data dictionary provides information about database objects, the server no longer checks directory names in the data directory to find databases. Consequently, the <kbd>--ignore-db-dir</kbd> option and <kbd>ignore_db_dirs</kbd> system variable are extraneous and have been removed. Update system configurations and application programs accordingly.</p>
</blockquote>



<p>As a result, all files in the data directory volume, in addition to the directories, are mistakenly recognized as database tables&#8211;for example, the <code>mysql.sock</code> file, which is created by Docker.</p>



<span id="more-3333"></span>



<p>The solution is to separate the actual database tables from the metadata files. We need to move all table files to a dedicated data directory and configure MySQL to use this new location.<br />Then let&#8217;s move all database data to dedicated data dir:</p>


<pre class="wp-block-code"><span><code class="hljs">mkdir data
mv * ./data/</code></span></pre>


<p>And specify the <em>dataDir</em> in my.cnf:<br /><code>datadir=/var/lib/mysql/data</code></p>



<p>Now MySql will only look for database table files in this directory and Docker still can write to the main MySql directory.<br />And, most importantly, the database will start up again.</p>



<p></p>The post <a href="https://nerdpress.org/2024/09/13/invalid-table-or-database-name-mysql-sock/">Invalid table or database name mysql.sock</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Import data into MySql with docker-compose</title>
		<link>https://nerdpress.org/2023/02/24/import-data-into-mysql-with-docker-compose/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 24 Feb 2023 10:04:31 +0000</pubDate>
				<category><![CDATA[docker-compose]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHPStorm]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3221</guid>

					<description><![CDATA[<p>Having a docker-compose setup which involves a Database like Mysql or MariaDB, then at some point you might want to import data into those Databases. There are several ways to import the data in your docker-compose setup. So let&#8217;s see how we can do this: 1. Using a volume for import data This applies to &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2023/02/24/import-data-into-mysql-with-docker-compose/" class="more-link">Continue reading<span class="screen-reader-text"> "Import data into MySql with docker-compose"</span></a></p>
The post <a href="https://nerdpress.org/2023/02/24/import-data-into-mysql-with-docker-compose/">Import data into MySql with docker-compose</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Having a docker-compose setup which involves a Database like Mysql or MariaDB, then at some point you might want to import data into those Databases.</p>



<p>There are several ways to import the data in your docker-compose setup.</p>



<ol class="wp-block-list">
<li>Using a volume for import data</li>



<li>Using mysql client from commandline with docker-compose exec</li>



<li>Using phpmyadmin in docker-compose setup</li>



<li>Using a mysql GUI client on the host and connect to the DB in the Docker container</li>
</ol>



<p>So let&#8217;s see how we can do this:</p>



<span id="more-3221"></span>



<h2 class="wp-block-heading">1. Using a volume for import data</h2>



<p>This applies to both official <a href="https://hub.docker.com/_/mysql/" target="_blank" rel="noopener" title="">Mysql</a><em> and <a href="https://hub.docker.com/_/mariadb/" target="_blank" rel="noopener" title="">MariaDB</a></em> official images.<br />These have builtin import mechanism to import data.<br />To quote from the docs:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory</p>
</blockquote>



<p>So all dumps that are found in the <em>/docker-entrypoint-initdb.d</em> directory of the image will be imported unless the database already contains data.</p>



<p>So let&#8217;s add this volume to our docker-compose.yaml</p>



<p><code>volumes: - ./database_dump.sql:/docker-entrypoint-initdb.d/datadump.sql</code></p>



<p>On next <code>docker-compose up</code> the data will be imported in your empty database.<br />You will see something like this in your docker-compose logs:</p>



<p>2023-02-06 15:40:16+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/database_dump.sql</p>



<p>Note: if there is already data in the database you need to clear the data first by f.e. clearing the volume, otherwise the import will not start:<br />You can clear all volumes of your docker-compose setup with (caution: this will clear <em>all</em> volumes, not just the database volume):</p>



<p><code>docker-compose down -v</code></p>



<h2 class="wp-block-heading">2. Using mysql client from commandline with docker-compose exec</h2>



<p>With this one liner you can import a SQL dump from a docker image that has a MySql/MariaDB client installed and are linked to the DB container:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">docker-compose exec my-app bash -c <span class="hljs-string">"mysql -u root -h mysql --password=root database &lt; database_dump.sql"</span></code></span></pre>


<p>This will execute the application image and import the data with the mysql client which connects to the host <code>mysql</code> which is the linked mysql container.</p>



<h2 class="wp-block-heading">3. Use phpmyadmin in docker-compose setup</h2>



<p>If the above is too consolish then you also can just add a phpmyaadmin container in your docker-compose setup and administer the database with a GUI from the browser.</p>


<pre class="wp-block-code"><span><code class="hljs">  myproject_phpmyadmin:
	image: phpmyadmin/phpmyadmin:latest
	ports:
	  - 8080:80
	environment:
	  PMA_HOST: myproject_mysql</code></span></pre>


<p>Then you can just open <em>http://localhost:8080</em> in the browser and log into to Phpmyadmin.<br />To import data go to the import tab and upload the dump file.</p>



<figure class="wp-block-image size-full"><a href="https://nerdpress.org/wp-content/uploads/2023/02/phpmyadmin_import_tab.png"><img decoding="async" width="481" height="51" src="https://nerdpress.org/wp-content/uploads/2023/02/phpmyadmin_import_tab.png" alt="" class="wp-image-3222" srcset="https://nerdpress.org/wp-content/uploads/2023/02/phpmyadmin_import_tab.png 481w, https://nerdpress.org/wp-content/uploads/2023/02/phpmyadmin_import_tab-300x32.png 300w" sizes="(max-width: 481px) 100vw, 481px" /></a><figcaption class="wp-element-caption">PhpMyAdmin Import tab</figcaption></figure>



<h2 class="wp-block-heading">4. Using a mysql GUI client on the host and connect to the DB in the Docker container</h2>



<p>For this approach you just need to open a port in the database container to the outside and use this port with localhost in the settings of your database client.</p>


<pre class="wp-block-code"><span><code class="hljs language-php">  myproject_mysql:
    image: mysql:<span class="hljs-number">5.7</span>
    hostname: mysql.${DOMAIN}
    container_name: ${CONTAINER_NAME}.mysql
      volumes:
	- ${PWD}/data/mysql/:/<span class="hljs-keyword">var</span>/lib/mysql
	- ./container/mysql/my.cnf:/etc/mysql/conf.d/z_my.cnf
    ports: <span class="hljs-comment"># open the mysql port to the host</span>
      - <span class="hljs-string">"3306:3306"</span>
    environment:
  ...</code></span></pre>


<p>See this screenshot from IntellIj&#8217;s PHPStorm Database tool:</p>



<figure class="wp-block-image size-full"><a href="https://nerdpress.org/wp-content/uploads/2023/02/PHPStorm_Database_property.png"><img fetchpriority="high" decoding="async" width="807" height="491" src="https://nerdpress.org/wp-content/uploads/2023/02/PHPStorm_Database_property.png" alt="" class="wp-image-3223" srcset="https://nerdpress.org/wp-content/uploads/2023/02/PHPStorm_Database_property.png 807w, https://nerdpress.org/wp-content/uploads/2023/02/PHPStorm_Database_property-300x183.png 300w, https://nerdpress.org/wp-content/uploads/2023/02/PHPStorm_Database_property-768x467.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></a><figcaption class="wp-element-caption">PHPStorm DB settings</figcaption></figure>



<p>From my experience these clients are very good to check data but not so good for import, at least I had rather poor experience in the PHPStorm DB Tool.<br />So going consolish on imports is recommended :)</p>The post <a href="https://nerdpress.org/2023/02/24/import-data-into-mysql-with-docker-compose/">Import data into MySql with docker-compose</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Migrating user table from Mysql to Postgres with Symfony and Doctrine</title>
		<link>https://nerdpress.org/2021/11/10/migrating-user-table-from-mysql-to-postgres-with-symfony-and-doctrine/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Wed, 10 Nov 2021 08:46:07 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Postgres]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3087</guid>

					<description><![CDATA[<p>When using bin/console make:entity on Mysql and then later you switch your application to Postgres and you have a table called user, which you most likely have when using security component of Symfony.Then you will receive an error because user is a reserved word in Postgres! An exception occurred while executing 'INSERT INTO user (id, &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2021/11/10/migrating-user-table-from-mysql-to-postgres-with-symfony-and-doctrine/" class="more-link">Continue reading<span class="screen-reader-text"> "Migrating user table from Mysql to Postgres with Symfony and Doctrine"</span></a></p>
The post <a href="https://nerdpress.org/2021/11/10/migrating-user-table-from-mysql-to-postgres-with-symfony-and-doctrine/">Migrating user table from Mysql to Postgres with Symfony and Doctrine</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>When using <code>bin/console make:entity</code> on Mysql and then later you switch your application to Postgres and you have a table called <code>user</code>, which you most likely have when using security component of Symfony.<br />Then you will receive an error because <code>user</code> is a reserved word in Postgres!</p>



<p><code>An exception occurred while executing 'INSERT INTO user (id, email, roles, password, is_verified) VALUES (?, ?, ?, ?, ?)' with params [3, "dev@dev.de", "[]", "your-encrypted-password", 0]:<br />SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "user"<br />LINE 1: INSERT INTO user (id, email, roles, password, is_verified) V...</code></p>



<span id="more-3087"></span>



<p>To fix this you have to escape the table name on your entity, fe. User.php:<br /><br />@<code>ORM\Table(name="`user`")</code></p>



<p>(<strong>note the backticks inside the quotes!)</strong></p>



<p>If you generate the entity with <a href="https://symfony.com/bundles/SymfonyMakerBundle/current/index.html" target="_blank" rel="noreferrer noopener">maker bundle</a>: <code>bin/console make:entity</code> directly on Postgres the backticks are added automatically.<br />But not when you switch the DB type. Then you have to add them manually. :)</p>



<p><br /></p>The post <a href="https://nerdpress.org/2021/11/10/migrating-user-table-from-mysql-to-postgres-with-symfony-and-doctrine/">Migrating user table from Mysql to Postgres with Symfony and Doctrine</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Sqlite Administration in IntelliJ IDE</title>
		<link>https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 17 May 2021 05:51:21 +0000</pubDate>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[Sqlite]]></category>
		<category><![CDATA[IntelliJ Ultimate]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3050</guid>

					<description><![CDATA[<p>Sometime ago I tried to use Adminer in Docker to administrate a sqlite database, which was not as easy as expected.If you are a happy user of IntelliJ IDE like PHPStorm or IntelliJ Ultimate like me :) then i would nowadays recommend to use the built-in database tool of your IntelliJ IDE for Sqlite administration &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/" class="more-link">Continue reading<span class="screen-reader-text"> "Sqlite Administration in IntelliJ IDE"</span></a></p>
The post <a href="https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/">Sqlite Administration in IntelliJ IDE</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Sometime ago I tried to use <a href="https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/" target="_blank" rel="noreferrer noopener">Adminer in Docker</a> to administrate a sqlite database, which was not as easy as expected.<br />If you are a happy user of IntelliJ IDE like PHPStorm or IntelliJ Ultimate like me :) then i would nowadays recommend to use the built-in database tool of your IntelliJ IDE for Sqlite administration instead.<br />Even in dockerized context.</p>



<span id="more-3050"></span>



<p>A Sqlite database is only one file, which you surely have access to.<br />So just add a Database configuration to your IDE and point it to the Sqlite file.<br />Click on the Database flyout on the left side then on the + (Plus) and add a Sqlite configuration.<br />(IntelliJ has good documentation on <a href="https://www.jetbrains.com/help/idea/connecting-to-a-database.html#connect-to-sqlite-database" target="_blank" rel="noreferrer noopener">Sqlite Database connection</a> as well of course)</p>



<figure class="wp-block-image size-large"><a href="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database.png"><img decoding="async" width="1024" height="563" src="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database-1024x563.png" alt="" class="wp-image-3051" srcset="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database-1024x563.png 1024w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database-300x165.png 300w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database-768x422.png 768w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database.png 1257w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></a></figure>



<p>Then you are ready to go.<br />The UI of the database structure is quite good.<br />You can browse the tables by doublelick on the table in the database structure view.<br />Also you can edit values in the table view.<br />Note: <em>When the DB was created inside the Docker container you probably dont own the DB from the host and you wont be able write to it.<br />While developing just change permissions on the host, if necessary.</em></p>



<p>You can also open a <strong>Database Console</strong> window where you can test queries.<br />This is particular better than using Adminer because these test queries are persisted and will still be there the next day.<br />You can add multiple database consoles and reopen them from &#8220;Scratches and Consoles&#8221; in your Project menu.</p>



<figure class="wp-block-image size-large"><a href="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console.png"><img decoding="async" width="1024" height="447" src="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console-1024x447.png" alt="" class="wp-image-3052" srcset="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console-1024x447.png 1024w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console-300x131.png 300w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console-768x335.png 768w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console.png 1434w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></a></figure>



<p>So no Adminer needed. Sqlite is just a file, dude.<br />No hassles with docker-compose anymore for DB administration and still using Docker for the app. :)</p>



<p><strong>Update 09.08.2023:</strong><br />JetBrains has now also uploaded a nice Youtube Video Tutorial on how to deal with Sqlite databases in IntelliJ IDEs like f.e. PHPStorm:<br /><a href="https://www.youtube.com/watch?v=Qw_JniULJBI" target="_blank" rel="noopener" title="">Working with SQLite Databases in any JetBrains IDE</a></p>



<p>I learned that you can now Drag and Drop Sqlite database files into the DataBase Pane and the IDE connects it directly, nice!</p>



<p></p>The post <a href="https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/">Sqlite Administration in IntelliJ IDE</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Docker-compose and Unknown MySQL server host</title>
		<link>https://nerdpress.org/2020/12/08/docker-compose-and-unknown-mysql-server-host/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 08 Dec 2020 10:06:25 +0000</pubDate>
				<category><![CDATA[docker]]></category>
		<category><![CDATA[docker-compose]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2962</guid>

					<description><![CDATA[<p>In case you encounter this error with mysql and your docker-compose setup: &#8230; and you dont know why because everything seems to be correct. Then you might have an upgrade problem with mysql because you are reusing an old volume that was created for another mysql version.This can happen when you use a unspecified tag &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2020/12/08/docker-compose-and-unknown-mysql-server-host/" class="more-link">Continue reading<span class="screen-reader-text"> "Docker-compose and Unknown MySQL server host"</span></a></p>
The post <a href="https://nerdpress.org/2020/12/08/docker-compose-and-unknown-mysql-server-host/">Docker-compose and Unknown MySQL server host</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>In case you encounter this error with mysql and your docker-compose setup:</p>


<pre class="wp-block-code"><span><code class="hljs language-xml">Unknown MySQL server host <span class="hljs-tag">&lt;<span class="hljs-name">mysql-service-name</span>&gt;</span></code></span></pre>


<p>&#8230; and you dont know why because everything seems to be correct.</p>



<p>Then you might have an upgrade problem with mysql because you are reusing an old volume that was created for another mysql version.<br>This can happen when you use a unspecified tag as <code>mysql:latest</code> (not recommended anyway) and there was a version bump in the official mysql image. <br>Or you upgraded the mysql container yourself, f.e. from <code>mysql:5.6</code> to <code>mysql:5.7</code> and you are reusing the data volume with the mysql files.</p>



<span id="more-2962"></span>



<p>When you check the startup logs you might see that mysql container is shutting down after startup because of an error like this:</p>


<pre class="wp-block-code"><span><code class="hljs">Can't open the mysql.plugin table. Please run mysql_upgrade to create it.</code></span></pre>


<p>You can run the upgrade command in the container:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">docker exec -it mysql_container_name bash -c <span class="hljs-string">"mysql_upgrade -uroot -proot"</span></code></span></pre>


<p>Or simply delete the volume and recreate it.<br><em>Note: the data will unfortunatly be lost. So better dump the data before deleting the volume and reimport it.</em><br>In my case its no problem because im starting a new project anyway.</p>



<p>To delete the volume you can:</p>


<pre class="wp-block-code"><span><code class="hljs language-xml">docker volume rm <span class="hljs-tag">&lt;<span class="hljs-name">volume</span> <span class="hljs-attr">id</span>&gt;</span></code></span></pre>


<p>Or just delete the data dir:</p>


<pre class="wp-block-code"><span><code class="hljs">rm -rf ./data/mysql</code></span></pre>


<p>Then restart your setup so the mysql container recreates the databases:</p>


<pre class="wp-block-code"><span><code class="hljs">docker-compose up</code></span></pre>


<p>and mysql is working again and the application is able to connect. :)</p>The post <a href="https://nerdpress.org/2020/12/08/docker-compose-and-unknown-mysql-server-host/">Docker-compose and Unknown MySQL server host</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Adminer for Sqlite in Docker</title>
		<link>https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Wed, 23 Oct 2019 08:02:47 +0000</pubDate>
				<category><![CDATA[docker]]></category>
		<category><![CDATA[Sqlite]]></category>
		<category><![CDATA[adminer]]></category>
		<category><![CDATA[docker-compose]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2889</guid>

					<description><![CDATA[<p>Recently i wanted to use Sqlite with Adminer in Docker and it turned out to be not so easy. I actually thought i could just declare Adminer in a docker-compose.yml file with a volume mounted, similar as i would do for adminer with mysql. Update: Today i would rather use the IntelliJ Database Tool for &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/" class="more-link">Continue reading<span class="screen-reader-text"> "Adminer for Sqlite in Docker"</span></a></p>
The post <a href="https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/">Adminer for Sqlite in Docker</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Recently i wanted to use Sqlite with <a aria-label="Adminer (opens in a new tab)" href="https://www.adminer.org/" target="_blank" rel="noreferrer noopener">Adminer</a> in Docker and it turned out to be not so easy.<br /> I actually thought i could just declare Adminer in a docker-compose.yml file with a volume mounted, similar as i would do for adminer with mysql.</p>



<p><strong>Update</strong>: Today i would rather use the <a href="https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/">IntelliJ Database Tool for Sqlite administration</a>.</p>



<p>But since Adminer is a popular hacking target they introduced a <a href="https://www.adminer.org/en/password/" target="_blank" rel="noreferrer noopener" aria-label="feature (opens in a new tab)">feature</a> that does not allow to run adminer without a password, out of the box.<br /> Sqlite database usually runs without password and dang, workaround needed!</p>



<span id="more-2889"></span>



<p>So we need to add a plugin to adminer that allows password-less login and extend the official Adminer Docker image to include the plugin.</p>



<p>We add a script that loads the official password-less-login plugin and copy it to the plugins-enabled folder of the Adminer image</p>



<p>login-password-less.php:</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:100%"><div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
&lt;?php
require_once(&#039;plugins/login-password-less.php&#039;);

/** Set allowed password
 * @param string result of password_hash
 */
return new AdminerLoginPasswordLess(
    $password_hash = password_hash(&quot;admin&quot;, PASSWORD_DEFAULT)
);
</pre></div></div>
</div>



<p>Dockerfile:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
FROM adminer
USER root
COPY login-password-less.php /var/www/html/plugins-enabled/login-password-less.php
#USER adminer # we run as root because of permissions problems on db file with the volume
</pre></div>


<p>In docker-compose.yml:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
version: &quot;3&quot;
services:
  app:
    build: ./php
      - mailcatcher
    volumes:
      - &quot;../:/app:rw&quot;
      - &quot;./php/cli/php.ini:/etc/php/7.3/cli/php.ini:ro&quot;
      - &quot;./php/fpm/php.ini:/etc/php/7.3/fpm/php.ini:ro&quot;

  nginx:
    build: ./nginx
    depends_on:
      - app
    command: /bin/sh -c &quot;nginx -g &#039;daemon off;&#039;&quot;
    volumes:
      - &quot;..:/app:rw&quot;
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    ports:
      - &#039;8088:80&#039;

  adminer:
    build: ./adminer
    restart: unless-stopped
    volumes:
      - &quot;..:/app:rw&quot;
    ports:
      - 8080:8080
</pre></div>


<p>File tree:</p>



<ul class="wp-block-list"><li>adminer<br />&#8211; Dockerfile<br />&#8211; login-password-less.php</li><li>nginx<br />&#8230;</li><li>php<br />&#8230;</li><li>docker-compose.yml</li></ul>



<p><em>Note that since docker-compose.yml version 3 the volumes_from directive was removed in favor of top level volumes to share volumes across images. However this implementation is imho rather weird, so i jut duplicated the volumes declaration in the App container and Adminer container.<br /> Feels rather wrong but thats all i could come up with. Any advice here is welcome.</em></p>



<p>Now that this is done we can open the Sqlite3 database with the pseudo-password &#8220;admin&#8221; and manage the database.</p>



<p>After all you could also just copy the one-file Adminer with plugin to the php container and run it from within the php container. Just adjust your Nginx config to allow calling the file directly and take care to not deploy Adminer to live.<br /> There is also a project that bundles the plugin with Adminer to one file: <a href="https://github.com/FrancoisCapon/LoginToASqlite3DatabaseWithoutCredentialsWithAdminer" target="_blank" rel="noreferrer noopener">https://github.com/FrancoisCapon/LoginToASqlite3DatabaseWithoutCredentialsWithAdminer/blob/master/build-adminer-4-sqlite3-into-one-file.sh</a></p>The post <a href="https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/">Adminer for Sqlite in Docker</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Silex and MongoDB simply</title>
		<link>https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/</link>
					<comments>https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 30 Jan 2012 14:27:34 +0000</pubDate>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Silex]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[silex]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2033</guid>

					<description><![CDATA[<p>Using MongoDB in your Silex Project is quite easy. I will show this with my Superleansilexplate and will integrate it there as an example. Since i dont want to integrate MongoDB in Superleansilexplate it will just become an additional gist. Given you have some smaller amount of data like a counter that needs to be &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/" class="more-link">Continue reading<span class="screen-reader-text"> "Silex and MongoDB simply"</span></a></p>
The post <a href="https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/">Silex and MongoDB simply</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Using MongoDB in your Silex Project is quite easy.</p>
<p>I will show this with my <a href="https://github.com/ivoba/superleansilexplate">Superleansilexplate</a> and will integrate it there as an example.<br />
Since i dont want to integrate MongoDB in Superleansilexplate it will just become an additional <a href="https://gist.github.com/1704512">gist</a>.</p>
<p>Given you have some smaller amount of data like a counter that needs to be stored or other loose coupled datasets, we simply speak to MongoDB &#8220;directly&#8221; and store the data via <a href="https://github.com/doctrine/mongodb">Doctrine MongoDB Abstraction Layer</a>.<br />
Since i presume the Data / Document Structure isnt that complex we dont use <a href="https://github.com/doctrine/mongodb-odm">Doctrine MongoDB ODM</a> (the Object Document Mapper).<br />
If you want to use it instead, try this <a href="https://github.com/docteurklein/SilexExtensions">Silex Extensions</a>.</p>
<p><span id="more-2033"></span></p>
<p>So we use this <a href="https://github.com/fate/Silex-Extensions">SilexExtensions</a> collection and install it via git:</p>
<pre class="brush: bash; title: ; notranslate">
 cd mysilexproject
 git clone git@github.com:fate/Silex-Extensions.git vendor/silex-extension
</pre>
<p>Then we install the doctrine mongodb libary manually:</p>
<pre class="brush: bash; title: ; notranslate">
 git clone --recursive https://github.com/doctrine/mongodb vendor/mongodb
</pre>
<p>The extension collection has some more poviders but you can just ignore them and just focus on the MongoDbExtension.</p>
<p>&#8211;<em> i actually dont like extensions collections. i would prefer to clone each extensions individually. thou its not much code overhead, but when it comes to the vendor dependencies it can become quite messy IMHO</em> &#8211;</p>
<p>Alright now the code.<br />
Edit src/app.php and register the namespace for the extension:</p>
<pre class="brush: php; title: ; notranslate">
 $app&#x5B;'autoloader']-&gt;registerNamespace('SilexExtension', __DIR__ . '/../vendor/silex-extension/src');
</pre>
<p>Then register the MongoDbExtension;</p>
<pre class="brush: php; title: ; notranslate">
 $app-&gt;register(new SilexExtension\MongoDbExtension(), array(
 'mongodb.class_path' =&gt; __DIR__ . '/../vendor/mongodb/lib',
 'mongodb.connection' =&gt; array(
 'server' =&gt; 'mongodb://mysecretuser:mysecretpassw@localhost',
 'options' =&gt; array(),
 'eventmanager' =&gt; function($eventmanager) {
 }
 )
 ));
</pre>
<p>and finally query your MongoDB collection of choice and display the resultset as json:</p>
<pre class="brush: php; title: ; notranslate">
$app-&gt;get('/data-from-mongodb', function() use($app) {

$coll = $app&#x5B;'mongodb']-&gt;selectDatabase('mydb')-&gt;selectCollection('mycoll');
 $query = array(
 'query' =&gt; 'value'
 );
 $sort = array(
 'count' =&gt; -1,
 );
 $r = $coll-&gt;find($query)-&gt;sort($sort)-&gt;toArray();
 $response = new Response();
 $response-&gt;headers-&gt;set('Content-type', 'application/json');
 $response-&gt;setContent(json_encode($r));
 return $response;
 });
</pre>
<p>Easy</p>The post <a href="https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/">Silex and MongoDB simply</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Migrate to Mongolab</title>
		<link>https://nerdpress.org/2011/09/26/migrate-to-mongolab/</link>
					<comments>https://nerdpress.org/2011/09/26/migrate-to-mongolab/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 26 Sep 2011 05:38:07 +0000</pubDate>
				<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[vServer]]></category>
		<category><![CDATA[mongodb]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1738</guid>

					<description><![CDATA[<p>Recently i ran into RAM troubles on my vserver for some reasons, i encountered the evil: Cannot allocate memory at ... So first i suspected mongodb to use up loads of memory as top showed. But after some recherche work i learned mongodb only -seems- to use a lot of memory. see here and here &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2011/09/26/migrate-to-mongolab/" class="more-link">Continue reading<span class="screen-reader-text"> "Migrate to Mongolab"</span></a></p>
The post <a href="https://nerdpress.org/2011/09/26/migrate-to-mongolab/">Migrate to Mongolab</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Recently i ran into RAM troubles on my vserver for some reasons, i encountered the evil:</p>
<pre class="brush: bash; title: ; notranslate">
Cannot allocate memory at ...
</pre>
<p>So first i suspected <a href="http://www.mongodb.org/">mongodb</a> to use up loads of memory as top showed.</p>
<p>But after some recherche work i learned mongodb only -seems- to use a lot of memory.<br />
see <a href="http://blog.mongodb.org/post/101911655/mongo-db-memory-usage">here</a> and <a href="http://www.mongodb.org/display/DOCS/Checking+Server+Memory+Usage">here</a> and <a href="http://stackoverflow.com/questions/4918443/is-it-ideal-that-mongodb-is-using-150-mb-memory/4918676#4918676">here</a><br />
The actual usage was around 20mb RAM, so mongodb was innocent.</p>
<p>The true RAM monsters were some apache and php-fpm zombies, but thats another story.</p>
<p>While suspecting mongodb i thought about outsourcing the mongodb and i found a free and sufficient offer in <a href="https://mongolab.com">mongolab</a>.<br />
My interests were on and i gave it a try.<br />
The free version has a limit for up to 240MB storage and since my app is just a small counter it should last for some time.<br />
<span id="more-1738"></span></p>
<p>The registration was easy, creation of the database aswell and the administration panel is also pretty cool and informative.<br />
<img decoding="async" class="alignnone size-medium wp-image-1743" style="border-style: initial; border-color: initial;" title="mongolab" src="https://nerdpress.org/wp-content/uploads/2011/09/mongolab-300x167.png" alt="" width="300" height="167" srcset="https://nerdpress.org/wp-content/uploads/2011/09/mongolab-300x167.png 300w, https://nerdpress.org/wp-content/uploads/2011/09/mongolab.png 816w" sizes="(max-width: 300px) 100vw, 300px" /><br />
Then create a user and migrate:</p>
<p>First get my data from the vserver on the vserver:</p>
<pre class="brush: bash; title: ; notranslate">
 mongodump --host 127.0.0.1
</pre>
<p>Then fetch it to my local machine:</p>
<pre class="brush: bash; title: ; notranslate">
 scp -r me@vserver.de:/var/www/vhosts/verrueckte/dump/mongodumpdata .
</pre>
<p>Ups i didnt had no mongo client on my local machine, go get it:</p>
<pre class="brush: bash; title: ; notranslate">
 sudo apt-get install mongodb-clients
</pre>
<p>Now connect to the mongolab via your console</p>
<pre class="brush: bash; title: ; notranslate">
 mongo db123xyz.mongolab.com:12345/thedb -u &lt;user&gt; -p &lt;pw&gt;
</pre>
<p>Hey works, great!<br />
Alright see you later.</p>
<pre class="brush: bash; title: ; notranslate">
 &gt; exit;
</pre>
<p>Now import the dumps to continue the counter there were i stopped.</p>
<pre class="brush: bash; title: ; notranslate">
 cd mongodumpdata
 mongorestore -h db123xyz.mongolab.com:12345 -d thedb -u -p .
</pre>
<p>Good!</p>
<p>Then teach the php app the new connection:</p>
<pre class="brush: php; title: ; notranslate">
 $this-&gt;host = 'mongodb://user:pw@db123xyz.mongolab.com:12345/thedb';
 new mongo($this-&gt;host);
</pre>
<p>There you go! The counter is storing its stuff to the mongolab database.<br />
And i can stop the mongod on my machine and free some memory.</p>
<pre class="brush: bash; title: ; notranslate">
 ps aux | grep mongodb
 kill &lt;PID&gt;
</pre>The post <a href="https://nerdpress.org/2011/09/26/migrate-to-mongolab/">Migrate to Mongolab</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2011/09/26/migrate-to-mongolab/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>[Symfony 2] Security Bundle &#8211; Benutzer mit username oder email anmelden.</title>
		<link>https://nerdpress.org/2011/08/12/symfony-2-security-bundle-benutzer-mit-username-oder-email-anmelden/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 12 Aug 2011 13:04:36 +0000</pubDate>
				<category><![CDATA[DB]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project Setup]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Doctrine 2]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SecurityBundle]]></category>
		<category><![CDATA[symfony 2]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1566</guid>

					<description><![CDATA[<p>Augenscheinlich unterstützt das Security-Modul in der Standard-Konfiguration nur die Authentifizierung via Benutzername und Password. Wie man sich mit einem Benutzernamen ODER der E-Mail-Adresse und einem Passwort authentifiziert, ist ein wenig versteckt. Das ist die Anleitung, wie es funktioniert.</p>
The post <a href="https://nerdpress.org/2011/08/12/symfony-2-security-bundle-benutzer-mit-username-oder-email-anmelden/">[Symfony 2] Security Bundle – Benutzer mit username oder email anmelden.</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Augenscheinlich unterstützt das Security-Module nur die Authentifizierung via Benutzername und Password. Wie man sich mit einem Benutzernamen ODER der E-Mail-Adresse und einem Password authentifiziert, ist ein wenig versteckt. So gehts:</p>
<p><span id="more-1566"></span></p>
<p>Schaut man sich den generischen EntityUserProvider an, so sieht man ab Zeile 46 sowas wie</p>
<pre class="brush: php; title: ; notranslate">
    /**
     * {@inheritdoc}
     */
    public function loadUserByUsername($username)
    {
        if (null !== $this-&gt;property) {
            $user = $this-&gt;repository-&gt;findOneBy(array($this-&gt;property =&gt; $username));
        } else {
            if (!$this-&gt;repository instanceof UserProviderInterface) {
                throw new InvalidArgumentException(sprintf('The Doctrine repository &quot;%s&quot; must implement UserProviderInterface.', get_class($this-&gt;repository)));
            }

            $user = $this-&gt;repository-&gt;loadUserByUsername($username);
        }

        if (null === $user) {
            throw new UsernameNotFoundException(sprintf('User &quot;%s&quot; not found.', $username));
        }

        return $user;
    }
</pre>
<p>Dieser Code besagt, dass nur dann, wenn die Konfigurationeinstellung &#8220;property&#8221; aus der security.yml entfernt wird (steht üblicherweise auf &#8220;username&#8221; und gibt das Datenbankattribut an, das eben den Benutzernamen hält), das entsprechende Doctrine-Entity &#8220;User&#8221; auch eine Repository-Class hat und diese darüber hinaus UserProviderInterface implementiert, man seine eigene loadUserByUsername()-Methode implementieren kann, die dann von der Firewall zur Identifizierung des Benutzer beim Login herangezogen wird (dieser Vorgang ist komplett intransparent, Symfony Magic).</p>
<p>Also aus seiner &#8220;alten&#8221; security.yml</p>
<pre class="brush: python; title: ; notranslate">
    providers:
        default:
            users:
                user:  { password: userpass, roles: &#x5B; 'ROLE_USER' ] }
                admin: { password: adminpass, roles: &#x5B; 'ROLE_ADMIN' ] }
            entity: { class: DvlpCoreBundleEntityUser, property: username }
</pre>
<p>sowas machen:</p>
<pre class="brush: python; title: ; notranslate">
     ...
            entity: { class: DvlpCoreBundleEntityUser }
</pre>
<p>Dann muss das zu User gehörtige UserRepository nur noch UserProviderInterface implementieren, bspw. so:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace DvlpCoreBundleEntity;

use DoctrineORMEntityRepository;
use SymfonyComponentSecurityCoreUserUserProviderInterface;
use SymfonyComponentSecurityCoreUserUserInterface;

/**
 * UserRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class UserRepository extends EntityRepository implements UserProviderInterface
{
    /**
     * {@inheritdoc}
     */
    public function loadUserByUsername($username)
    {
        return $this-&gt;getEntityManager()
            -&gt;createQuery('SELECT u FROM DvlpCoreBundle:User u JOIN u.Profile p WHERE u.username = :username OR p.email = :username')
            -&gt;setParameters(array(
                'username' =&gt; $username
            ))
            -&gt;getOneOrNullResult();
    }

    /**
     * {@inheritDoc}
     */
    public function refreshUser(UserInterface $user)
    {
        return $this-&gt;loadUserByUsername($user-&gt;getUsername());
    }

    /**
     * {@inheritDoc}
     */
    public function supportsClass($class)
    {
        // NEVER CALLED ...
        return $class === 'DvlpCoreBundleEntityUser';
    }
}
}
</pre>
<p>Schon kann man als Benutzernamen entweder den Username oder die E-Mail-Adresse des Users angeben.</p>The post <a href="https://nerdpress.org/2011/08/12/symfony-2-security-bundle-benutzer-mit-username-oder-email-anmelden/">[Symfony 2] Security Bundle – Benutzer mit username oder email anmelden.</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
