{"id":358,"date":"2018-09-13T08:04:05","date_gmt":"2018-09-13T06:04:05","guid":{"rendered":"https:\/\/ekiwi.de\/?p=358"},"modified":"2020-07-10T20:05:23","modified_gmt":"2020-07-10T18:05:23","slug":"umstellung-von-php-5-6-auf-php-7-scripte-mit-mysql","status":"publish","type":"post","link":"https:\/\/ekiwi.de\/index.php\/358\/umstellung-von-php-5-6-auf-php-7-scripte-mit-mysql\/","title":{"rendered":"Umstellung von PHP 5.6 auf PHP 7 &#8211; Scripte mit MySQL"},"content":{"rendered":"<p>Das Ende von PHP 5.6 naht in gro\u00dfen Schritten Ende diesen Jahres. Zuletzt hat unser Provider Hosteurope das Ende angek\u00fcndigt:<\/p>\n<p><!--more--><\/p>\n<p><quote>Die Standard PHP Version 5.6 wird am 24.10.2018 deaktiviert. Alle Domains\/Verzeichnisse, die zu diesem Zeitpunkt auf PHP 5.6 im KIS eingestellt sind, werden automatisch auf die neue Standard <a class=\"aawp-link\" href=\"https:\/\/www.amazon.de\/dp\/3836263955?tag=ekiwide0b-21&linkCode=ogi&th=1&psc=1\" title=\"Das Standardwerk \u00fcber PHP7 und MySQL\" target=\"_blank\" rel=\"nofollow noopener sponsored\"  data-aawp-product-asin=\"3836263955\" data-aawp-product-id=\"5235\" data-aawp-tracking-id=\"ekiwide0b-21\" data-aawp-product-title=\"PHP 7 und MySQL  Das umfassende Handbuch aktuell zu PHP 7.3 Dynamische Webseiten von den Grundlagen bis zur professionellen Programmierung\">PHP Version 7.2<\/a>&nbsp;<a class=\"aawp-link-icon-container\" href=\"https:\/\/www.amazon.de\/dp\/3836263955?tag=ekiwide0b-21&linkCode=ogi&th=1&psc=1\" title=\"Das Standardwerk \u00fcber PHP7 und MySQL\" target=\"_blank\" rel=\"nofollow noopener sponsored\"  data-aawp-product-asin=\"3836263955\" data-aawp-product-id=\"5235\" data-aawp-tracking-id=\"ekiwide0b-21\" data-aawp-product-title=\"PHP 7 und MySQL  Das umfassende Handbuch aktuell zu PHP 7.3 Dynamische Webseiten von den Grundlagen bis zur professionellen Programmierung\"><span class=\"aawp-link-icon cart\"><\/span><\/a> umgestellt.<\/quote><\/p>\n<p>Satte vier Jahre wurde PHP 5.6 unterst\u00fctzt. In Folge dessen sind viele Scripte darauf optimiert bzw. viele \u00e4ltere Scripte laufen, derzeit noch, hervorragend mit dieser Version, da diese noch zahlreiche Funktionen unterst\u00fctzt, welche bereits seit Jahren als &#8222;deprecated&#8220; bzw. veraltet gelten. So wie die alten MySQL-Funktionen. Wer eine Funktion wie <code>mysql_connect<\/code> aufruft, erhielt bereits ab PHP 5.5 folgende Warnung:<\/p>\n<pre>Deprecated: mysql_connect(): The mysql extension is deprecated and will be\r\nremoved in the future: use mysqli or PDO instead<\/pre>\n<p>Ausgegeben wird diese Warnung nur, wenn der Server entsprechend konfiguriert ist. Viele Server geben im Produktivbetrieb weder Hinweise und Warungen aus, oft auch keine Fehler. Hier verr\u00e4t erst der Blick in die Logfiles, dass hier ein Problem vorliegt. Die \u00dcberraschung ist gro\u00df, wenn pl\u00f6tzlich gar nichts mehr geht. Alte Scripte umzustellen ist nicht schwer. Der Aufwand h\u00e4ngt davon ab, wie der Entwickler das Script angelegt hat.<\/p>\n\n<div class=\"aawp\">\n\n            \n            \n<div class=\"aawp-product aawp-product--horizontal aawp-product--bestseller aawp-product--ribbon\"  data-aawp-product-asin=\"3367100005\" data-aawp-product-id=\"5218\" data-aawp-tracking-id=\"ekiwide0b-21\" data-aawp-product-title=\"PHP 8 und MySQL  Das umfassende Handbuch zu PHP 8 Dynamische Webseiten von den Grundlagen bis zur fortgeschrittenen PHP-Programmierung\">\n\n    <span class=\"aawp-product__ribbon aawp-product__ribbon--bestseller\">Bestseller Nr. 1<\/span>\n    <div class=\"aawp-product__thumb\">\n        <a class=\"aawp-product__image-link\"\n           href=\"https:\/\/www.amazon.de\/dp\/3367100005?tag=ekiwide0b-21&linkCode=ogi&th=1&psc=1&keywords=php\" title=\"PHP 8 und MySQL: Das umfassende Handbuch zu PHP...\" rel=\"nofollow noopener sponsored\" target=\"_blank\">\n            <img decoding=\"async\" class=\"aawp-product__image\" src=\"https:\/\/m.media-amazon.com\/images\/I\/51mKT2vT0rL._SL160_.jpg\" alt=\"PHP 8 und MySQL: Das umfassende Handbuch zu PHP...\"  \/>\n        <\/a>\n\n            <\/div>\n\n    <div class=\"aawp-product__content\">\n        <a class=\"aawp-product__title\" href=\"https:\/\/www.amazon.de\/dp\/3367100005?tag=ekiwide0b-21&linkCode=ogi&th=1&psc=1&keywords=php\" title=\"PHP 8 und MySQL: Das umfassende Handbuch zu PHP...\" rel=\"nofollow noopener sponsored\" target=\"_blank\">\n            PHP 8 und MySQL: Das umfassende Handbuch zu PHP...        <\/a>\n        <div class=\"aawp-product__description\">\n            <ul><li>Wenz, Christian(Autor)<\/li><\/ul>        <\/div>\n    <\/div>\n\n    <div class=\"aawp-product__footer\">\n\n        <div class=\"aawp-product__pricing\">\n            \n                            <span class=\"aawp-product__price aawp-product__price--current\"><\/span>\n            \n                    <\/div>\n\n                <a class=\"aawp-button aawp-button--buy aawp-button--icon aawp-button--icon-black\" href=\"https:\/\/www.amazon.de\/dp\/3367100005?tag=ekiwide0b-21&#038;linkCode=ogi&#038;th=1&#038;psc=1&#038;keywords=php\" title=\"Bei Amazon kaufen\" target=\"_blank\" rel=\"nofollow noopener sponsored\">Bei Amazon kaufen<\/a>\n            <\/div>\n\n<\/div>\n\n    \n<\/div>\n\n<p>Gibt es eine zentrale Datenbankklasse oder Datenbankschicht? Gut, dann m\u00fcssen nur hier \u00c4nderungen durchgef\u00fchrt werden. In den Anfangszeiten von PHP wurden Scripte meist frei nach Schnauze entwickelt, d.h. wurden Daten aus der Datenbank ben\u00f6tigt, wurde die Datenbankfunktion direkt aufgerufen. In diesem Fall sind die Funktionsaufrufe f\u00fcr MySQL in allen Scriptdateien enthalten. <\/p>\n<p>Die &#8222;Veraltet Meldung&#8220; verr\u00e4t bereits die L\u00f6sung: wir m\u00fcssen unser Script umstellen auf die neuen Datenbankfunktionen. Entweder <code>mysqli<\/code> oder die PDO-Funktionen. Am einfachsten geht die Umstellung aif <code>mysqli<\/code>. Hier muss einfach nur ein &#8222;i&#8220; eingef\u00fcgt werden. Aus <code>mysql_connect<\/code> wird <code>mysqli_connect<\/code>. Gleiches gilt f\u00fcr alle anderen <code>mysql_<\/code> Funktionen.<\/p>\n<pre>\r\n\/\/aus:\r\n$connection = mysql_connect('localhost', 'username', 'password');\r\n\/\/wird:\r\n$connection = mysqli_connect('localhost', 'username', 'password');\r\n<\/pre>\n<p>Die neue Funktion erlaubt auch gleich die Auswahl einer Datenbank:<\/p>\n<pre>\r\n$connection = mysqli_connect('localhost', 'username', 'password', 'database');\r\n<\/pre>\n<p>Das war einfach! Dennoch gibt es Fallstricke. Einige Funktionen haben eine andere Reihenfolge der Parameter. Dies sind die Funktionen, welche den Datenbanklink als Parameter verwenden, wie die Funktion <code>mysql_query<\/code>:<\/p>\n<pre>$result = mysql_query($sql,$db_link);<\/pre>\n<p>Die SQL-Abfrage war hier bisher der erste Parameter, die Datenbankverbindung der Zweite. Dies \u00e4ndert sich:<\/p>\n<pre>\r\n$result = mysqli_query($db, $sql);\r\n<\/pre>\n<p>Somit ist es mit einem simplen datei\u00fcbergreifenden Suchen und Ersetzen nicht getan, sofern man nicht in die Kiste der regul\u00e4ren Ausdr\u00fccke greift. <\/p>\n<p>Um ein Script umzustellen, m\u00fcssen also nur alle Vorkommen der MySQL-Funktionen im Quelltext gesucht und angepasst werden. Keine Raketenwissenschaft, sondern Flei\u00df. Anschlie\u00dfend l\u00e4uft das Script auch mit PHP 7 wieder, sofern nicht noch andere Funktionen angepasst werden m\u00fcssen.<\/p>\n\n<div class=\"aawp\">\n\n            \n            \n<div class=\"aawp-product aawp-product--horizontal aawp-product--bestseller aawp-product--ribbon\"  data-aawp-product-asin=\"3367100005\" data-aawp-product-id=\"5218\" data-aawp-tracking-id=\"ekiwide0b-21\" data-aawp-product-title=\"PHP 8 und MySQL  Das umfassende Handbuch zu PHP 8 Dynamische Webseiten von den Grundlagen bis zur fortgeschrittenen PHP-Programmierung\">\n\n    <span class=\"aawp-product__ribbon aawp-product__ribbon--bestseller\">Bestseller Nr. 1<\/span>\n    <div class=\"aawp-product__thumb\">\n        <a class=\"aawp-product__image-link\"\n           href=\"https:\/\/www.amazon.de\/dp\/3367100005?tag=ekiwide0b-21&linkCode=ogi&th=1&psc=1&keywords=php\" title=\"PHP 8 und MySQL: Das umfassende Handbuch zu PHP...\" rel=\"nofollow noopener sponsored\" target=\"_blank\">\n            <img decoding=\"async\" class=\"aawp-product__image\" src=\"https:\/\/m.media-amazon.com\/images\/I\/51mKT2vT0rL._SL160_.jpg\" alt=\"PHP 8 und MySQL: Das umfassende Handbuch zu PHP...\"  \/>\n        <\/a>\n\n            <\/div>\n\n    <div class=\"aawp-product__content\">\n        <a class=\"aawp-product__title\" href=\"https:\/\/www.amazon.de\/dp\/3367100005?tag=ekiwide0b-21&linkCode=ogi&th=1&psc=1&keywords=php\" title=\"PHP 8 und MySQL: Das umfassende Handbuch zu PHP...\" rel=\"nofollow noopener sponsored\" target=\"_blank\">\n            PHP 8 und MySQL: Das umfassende Handbuch zu PHP...        <\/a>\n        <div class=\"aawp-product__description\">\n            <ul><li>Wenz, Christian(Autor)<\/li><\/ul>        <\/div>\n    <\/div>\n\n    <div class=\"aawp-product__footer\">\n\n        <div class=\"aawp-product__pricing\">\n            \n                            <span class=\"aawp-product__price aawp-product__price--current\"><\/span>\n            \n                    <\/div>\n\n                <a class=\"aawp-button aawp-button--buy aawp-button--icon aawp-button--icon-black\" href=\"https:\/\/www.amazon.de\/dp\/3367100005?tag=ekiwide0b-21&#038;linkCode=ogi&#038;th=1&#038;psc=1&#038;keywords=php\" title=\"Bei Amazon kaufen\" target=\"_blank\" rel=\"nofollow noopener sponsored\">Bei Amazon kaufen<\/a>\n            <\/div>\n\n<\/div>\n\n            \n            \n<div class=\"aawp-product aawp-product--horizontal aawp-product--bestseller aawp-product--ribbon\"  data-aawp-product-asin=\"3836292742\" data-aawp-product-id=\"5222\" data-aawp-tracking-id=\"ekiwide0b-21\" data-aawp-product-title=\"Einstieg in PHP 8 und MySQL  Ideal f\u00fcr Programmieranf\u00e4nger ohne Vorwissen Schnell und einfach dynamische Webseiten entwickeln Inkl MariaDB\">\n\n    <span class=\"aawp-product__ribbon aawp-product__ribbon--bestseller\">Bestseller Nr. 2<\/span>\n    <div class=\"aawp-product__thumb\">\n        <a class=\"aawp-product__image-link\"\n           href=\"https:\/\/www.amazon.de\/dp\/3836292742?tag=ekiwide0b-21&linkCode=ogi&th=1&psc=1&keywords=php\" title=\"Einstieg in PHP 8 und MySQL: Ideal f\u00fcr...\" rel=\"nofollow noopener sponsored\" target=\"_blank\">\n            <img decoding=\"async\" class=\"aawp-product__image\" src=\"https:\/\/m.media-amazon.com\/images\/I\/51srBJ6k-9L._SL160_.jpg\" alt=\"Einstieg in PHP 8 und MySQL: Ideal f\u00fcr...\"  \/>\n        <\/a>\n\n            <\/div>\n\n    <div class=\"aawp-product__content\">\n        <a class=\"aawp-product__title\" href=\"https:\/\/www.amazon.de\/dp\/3836292742?tag=ekiwide0b-21&linkCode=ogi&th=1&psc=1&keywords=php\" title=\"Einstieg in PHP 8 und MySQL: Ideal f\u00fcr...\" rel=\"nofollow noopener sponsored\" target=\"_blank\">\n            Einstieg in PHP 8 und MySQL: Ideal f\u00fcr...        <\/a>\n        <div class=\"aawp-product__description\">\n            <ul><li>Theis, Thomas(Autor)<\/li><\/ul>        <\/div>\n    <\/div>\n\n    <div class=\"aawp-product__footer\">\n\n        <div class=\"aawp-product__pricing\">\n            \n                            <span class=\"aawp-product__price aawp-product__price--current\"><\/span>\n            \n                    <\/div>\n\n                <a class=\"aawp-button aawp-button--buy aawp-button--icon aawp-button--icon-black\" href=\"https:\/\/www.amazon.de\/dp\/3836292742?tag=ekiwide0b-21&#038;linkCode=ogi&#038;th=1&#038;psc=1&#038;keywords=php\" title=\"Bei Amazon kaufen\" target=\"_blank\" rel=\"nofollow noopener sponsored\">Bei Amazon kaufen<\/a>\n            <\/div>\n\n<\/div>\n\n    \n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Das Ende von PHP 5.6 naht in gro\u00dfen Schritten Ende diesen Jahres. Zuletzt hat unser Provider Hosteurope das Ende angek\u00fcndigt:<\/p>\n","protected":false},"author":1,"featured_media":57,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[14,13],"tags":[31,80],"class_list":["post-358","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-programmierung","tag-php","tag-programmierung"],"_links":{"self":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts\/358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/media\/57"}],"wp:attachment":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}