Move script from PHP 5.6 to PHP 7












0















I have a problem and I hope someone can help me solve it.



I had to upgrade my VPS and from CentOS 6.x I switched to CentOS 7.5
So now I find PHP 7.0.1 and MySQL 5.7



The script I write below, worked great on
PHP 5.6 and MariaDB and now goes wrong.



What can be a valid solution for this script to work properly?
Thank you all.



$connessione = mysql_connect("localhost", "myuser", "mypassword");
mysql_select_db("mydb", $connessione);
$risultato = mysql_query("SELECT * FROM mytable", $connessione);
$num_righe = mysql_num_rows($risultato);

if ($num_righe == 0) {
echo "There are no new products";
} else {

$query ="SELECT * FROM mytable";

$nuovi_prodotti= mysql_query($query, $connessione) or die(mysql_error());
$row_nuovi_prodotti = mysql_fetch_assoc($nuovi_prodotti);

$intes ="Riferimento|ID|nome|plain_description|iva inclusa|id_fornitore|brand|tax|picture1|picture2|picture3|model_size|model_quantity|barcode";
$fornitore ="1";
$iva = "22";

$righe.="".$intes."n";
do {
$righe.= "".$row_nuovi_prodotti['reference']."|".$row_nuovi_prodotti['id_categoria']."|".$row_nuovi_prodotti['descrizione']."|".$row_nuovi_prodotti['descrizione']."|".$row_nuovi_prodotti['prezzoacquisto']."|".$row_nuovi_prodotti['prezzovendita']."|".$fornitore."|".$row_nuovi_prodotti['marca']."|".$row_nuovi_prodotti['dispo']."|".$row_nuovi_prodotti['EAN']."|".$iva."|https://www.mysite.it/cat/".$row_nuovi_prodotti['reference'].".jpgn";
}
while ($row_nuovi_prodotti_unica= mysql_fetch_assoc($nuovi_prodotti_unica));
$filename = "nuovi-prodotti-tagliaunica.csv";
file_put_contents($filename, $righe);
echo "New products found: $num_righe - file CSV ok n";
}
mysql_close($connessione);









share|improve this question




















  • 1





    Turn on error reporting, then you will see the errors. Also, the mysql_* functions were deprecated in PHP 5.6, and completely removed in PHP7+.

    – Tobias F.
    Nov 21 '18 at 9:05






  • 1





    To build on Tobias F.'s comment, mysql_* was replaced with mysqli_* - bear in mind that it's not a simple find/replace job to upgrade from mysql_. You should look at the documentation on php.net for more info

    – Scoots
    Nov 21 '18 at 9:07








  • 3





    Possible duplicate of How to change mysql to mysqli?

    – ADyson
    Nov 21 '18 at 9:09











  • I have already opted for mysqli, but without any outcome. the requested page goes into error

    – Roberto
    Nov 21 '18 at 10:36











  • you're not using mysqli, although you're attempting to use mysqli syntax with the added database connection parameter. your mysql_* needs to be mysqli_*

    – Martin
    Nov 21 '18 at 12:00
















0















I have a problem and I hope someone can help me solve it.



I had to upgrade my VPS and from CentOS 6.x I switched to CentOS 7.5
So now I find PHP 7.0.1 and MySQL 5.7



The script I write below, worked great on
PHP 5.6 and MariaDB and now goes wrong.



What can be a valid solution for this script to work properly?
Thank you all.



$connessione = mysql_connect("localhost", "myuser", "mypassword");
mysql_select_db("mydb", $connessione);
$risultato = mysql_query("SELECT * FROM mytable", $connessione);
$num_righe = mysql_num_rows($risultato);

if ($num_righe == 0) {
echo "There are no new products";
} else {

$query ="SELECT * FROM mytable";

$nuovi_prodotti= mysql_query($query, $connessione) or die(mysql_error());
$row_nuovi_prodotti = mysql_fetch_assoc($nuovi_prodotti);

$intes ="Riferimento|ID|nome|plain_description|iva inclusa|id_fornitore|brand|tax|picture1|picture2|picture3|model_size|model_quantity|barcode";
$fornitore ="1";
$iva = "22";

$righe.="".$intes."n";
do {
$righe.= "".$row_nuovi_prodotti['reference']."|".$row_nuovi_prodotti['id_categoria']."|".$row_nuovi_prodotti['descrizione']."|".$row_nuovi_prodotti['descrizione']."|".$row_nuovi_prodotti['prezzoacquisto']."|".$row_nuovi_prodotti['prezzovendita']."|".$fornitore."|".$row_nuovi_prodotti['marca']."|".$row_nuovi_prodotti['dispo']."|".$row_nuovi_prodotti['EAN']."|".$iva."|https://www.mysite.it/cat/".$row_nuovi_prodotti['reference'].".jpgn";
}
while ($row_nuovi_prodotti_unica= mysql_fetch_assoc($nuovi_prodotti_unica));
$filename = "nuovi-prodotti-tagliaunica.csv";
file_put_contents($filename, $righe);
echo "New products found: $num_righe - file CSV ok n";
}
mysql_close($connessione);









share|improve this question




















  • 1





    Turn on error reporting, then you will see the errors. Also, the mysql_* functions were deprecated in PHP 5.6, and completely removed in PHP7+.

    – Tobias F.
    Nov 21 '18 at 9:05






  • 1





    To build on Tobias F.'s comment, mysql_* was replaced with mysqli_* - bear in mind that it's not a simple find/replace job to upgrade from mysql_. You should look at the documentation on php.net for more info

    – Scoots
    Nov 21 '18 at 9:07








  • 3





    Possible duplicate of How to change mysql to mysqli?

    – ADyson
    Nov 21 '18 at 9:09











  • I have already opted for mysqli, but without any outcome. the requested page goes into error

    – Roberto
    Nov 21 '18 at 10:36











  • you're not using mysqli, although you're attempting to use mysqli syntax with the added database connection parameter. your mysql_* needs to be mysqli_*

    – Martin
    Nov 21 '18 at 12:00














0












0








0








I have a problem and I hope someone can help me solve it.



I had to upgrade my VPS and from CentOS 6.x I switched to CentOS 7.5
So now I find PHP 7.0.1 and MySQL 5.7



The script I write below, worked great on
PHP 5.6 and MariaDB and now goes wrong.



What can be a valid solution for this script to work properly?
Thank you all.



$connessione = mysql_connect("localhost", "myuser", "mypassword");
mysql_select_db("mydb", $connessione);
$risultato = mysql_query("SELECT * FROM mytable", $connessione);
$num_righe = mysql_num_rows($risultato);

if ($num_righe == 0) {
echo "There are no new products";
} else {

$query ="SELECT * FROM mytable";

$nuovi_prodotti= mysql_query($query, $connessione) or die(mysql_error());
$row_nuovi_prodotti = mysql_fetch_assoc($nuovi_prodotti);

$intes ="Riferimento|ID|nome|plain_description|iva inclusa|id_fornitore|brand|tax|picture1|picture2|picture3|model_size|model_quantity|barcode";
$fornitore ="1";
$iva = "22";

$righe.="".$intes."n";
do {
$righe.= "".$row_nuovi_prodotti['reference']."|".$row_nuovi_prodotti['id_categoria']."|".$row_nuovi_prodotti['descrizione']."|".$row_nuovi_prodotti['descrizione']."|".$row_nuovi_prodotti['prezzoacquisto']."|".$row_nuovi_prodotti['prezzovendita']."|".$fornitore."|".$row_nuovi_prodotti['marca']."|".$row_nuovi_prodotti['dispo']."|".$row_nuovi_prodotti['EAN']."|".$iva."|https://www.mysite.it/cat/".$row_nuovi_prodotti['reference'].".jpgn";
}
while ($row_nuovi_prodotti_unica= mysql_fetch_assoc($nuovi_prodotti_unica));
$filename = "nuovi-prodotti-tagliaunica.csv";
file_put_contents($filename, $righe);
echo "New products found: $num_righe - file CSV ok n";
}
mysql_close($connessione);









share|improve this question
















I have a problem and I hope someone can help me solve it.



I had to upgrade my VPS and from CentOS 6.x I switched to CentOS 7.5
So now I find PHP 7.0.1 and MySQL 5.7



The script I write below, worked great on
PHP 5.6 and MariaDB and now goes wrong.



What can be a valid solution for this script to work properly?
Thank you all.



$connessione = mysql_connect("localhost", "myuser", "mypassword");
mysql_select_db("mydb", $connessione);
$risultato = mysql_query("SELECT * FROM mytable", $connessione);
$num_righe = mysql_num_rows($risultato);

if ($num_righe == 0) {
echo "There are no new products";
} else {

$query ="SELECT * FROM mytable";

$nuovi_prodotti= mysql_query($query, $connessione) or die(mysql_error());
$row_nuovi_prodotti = mysql_fetch_assoc($nuovi_prodotti);

$intes ="Riferimento|ID|nome|plain_description|iva inclusa|id_fornitore|brand|tax|picture1|picture2|picture3|model_size|model_quantity|barcode";
$fornitore ="1";
$iva = "22";

$righe.="".$intes."n";
do {
$righe.= "".$row_nuovi_prodotti['reference']."|".$row_nuovi_prodotti['id_categoria']."|".$row_nuovi_prodotti['descrizione']."|".$row_nuovi_prodotti['descrizione']."|".$row_nuovi_prodotti['prezzoacquisto']."|".$row_nuovi_prodotti['prezzovendita']."|".$fornitore."|".$row_nuovi_prodotti['marca']."|".$row_nuovi_prodotti['dispo']."|".$row_nuovi_prodotti['EAN']."|".$iva."|https://www.mysite.it/cat/".$row_nuovi_prodotti['reference'].".jpgn";
}
while ($row_nuovi_prodotti_unica= mysql_fetch_assoc($nuovi_prodotti_unica));
$filename = "nuovi-prodotti-tagliaunica.csv";
file_put_contents($filename, $righe);
echo "New products found: $num_righe - file CSV ok n";
}
mysql_close($connessione);






php mysql csv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 12:11









AntoineB

2,29811742




2,29811742










asked Nov 21 '18 at 9:01









RobertoRoberto

4




4








  • 1





    Turn on error reporting, then you will see the errors. Also, the mysql_* functions were deprecated in PHP 5.6, and completely removed in PHP7+.

    – Tobias F.
    Nov 21 '18 at 9:05






  • 1





    To build on Tobias F.'s comment, mysql_* was replaced with mysqli_* - bear in mind that it's not a simple find/replace job to upgrade from mysql_. You should look at the documentation on php.net for more info

    – Scoots
    Nov 21 '18 at 9:07








  • 3





    Possible duplicate of How to change mysql to mysqli?

    – ADyson
    Nov 21 '18 at 9:09











  • I have already opted for mysqli, but without any outcome. the requested page goes into error

    – Roberto
    Nov 21 '18 at 10:36











  • you're not using mysqli, although you're attempting to use mysqli syntax with the added database connection parameter. your mysql_* needs to be mysqli_*

    – Martin
    Nov 21 '18 at 12:00














  • 1





    Turn on error reporting, then you will see the errors. Also, the mysql_* functions were deprecated in PHP 5.6, and completely removed in PHP7+.

    – Tobias F.
    Nov 21 '18 at 9:05






  • 1





    To build on Tobias F.'s comment, mysql_* was replaced with mysqli_* - bear in mind that it's not a simple find/replace job to upgrade from mysql_. You should look at the documentation on php.net for more info

    – Scoots
    Nov 21 '18 at 9:07








  • 3





    Possible duplicate of How to change mysql to mysqli?

    – ADyson
    Nov 21 '18 at 9:09











  • I have already opted for mysqli, but without any outcome. the requested page goes into error

    – Roberto
    Nov 21 '18 at 10:36











  • you're not using mysqli, although you're attempting to use mysqli syntax with the added database connection parameter. your mysql_* needs to be mysqli_*

    – Martin
    Nov 21 '18 at 12:00








1




1





Turn on error reporting, then you will see the errors. Also, the mysql_* functions were deprecated in PHP 5.6, and completely removed in PHP7+.

– Tobias F.
Nov 21 '18 at 9:05





Turn on error reporting, then you will see the errors. Also, the mysql_* functions were deprecated in PHP 5.6, and completely removed in PHP7+.

– Tobias F.
Nov 21 '18 at 9:05




1




1





To build on Tobias F.'s comment, mysql_* was replaced with mysqli_* - bear in mind that it's not a simple find/replace job to upgrade from mysql_. You should look at the documentation on php.net for more info

– Scoots
Nov 21 '18 at 9:07







To build on Tobias F.'s comment, mysql_* was replaced with mysqli_* - bear in mind that it's not a simple find/replace job to upgrade from mysql_. You should look at the documentation on php.net for more info

– Scoots
Nov 21 '18 at 9:07






3




3





Possible duplicate of How to change mysql to mysqli?

– ADyson
Nov 21 '18 at 9:09





Possible duplicate of How to change mysql to mysqli?

– ADyson
Nov 21 '18 at 9:09













I have already opted for mysqli, but without any outcome. the requested page goes into error

– Roberto
Nov 21 '18 at 10:36





I have already opted for mysqli, but without any outcome. the requested page goes into error

– Roberto
Nov 21 '18 at 10:36













you're not using mysqli, although you're attempting to use mysqli syntax with the added database connection parameter. your mysql_* needs to be mysqli_*

– Martin
Nov 21 '18 at 12:00





you're not using mysqli, although you're attempting to use mysqli syntax with the added database connection parameter. your mysql_* needs to be mysqli_*

– Martin
Nov 21 '18 at 12:00












1 Answer
1






active

oldest

votes


















0














The problem occurs because the mysql_* syntax is deprecated in PHP 7.0 and forward. You will need to change to mysqli_* or PDO.



You mention in the comments that you "already opted for mysqli", but the syntax provided in your question is a mixed syntax of mysql and mysqli. mysqli takes the database connection as a parameter, while mysql does not.



Therefore, change your mysql_* to mysqli_*.



Examples from your question:



mysql_query($query, $connessione)



to



mysqli_query($query, $connessione)



etc.



If you're in doubt about what the syntax is for the different mysqli_* functions, then I would suggest looking it up. This thread is a good place to start if you're changing from mysql to mysqli.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408438%2fmove-script-from-php-5-6-to-php-7%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The problem occurs because the mysql_* syntax is deprecated in PHP 7.0 and forward. You will need to change to mysqli_* or PDO.



    You mention in the comments that you "already opted for mysqli", but the syntax provided in your question is a mixed syntax of mysql and mysqli. mysqli takes the database connection as a parameter, while mysql does not.



    Therefore, change your mysql_* to mysqli_*.



    Examples from your question:



    mysql_query($query, $connessione)



    to



    mysqli_query($query, $connessione)



    etc.



    If you're in doubt about what the syntax is for the different mysqli_* functions, then I would suggest looking it up. This thread is a good place to start if you're changing from mysql to mysqli.






    share|improve this answer




























      0














      The problem occurs because the mysql_* syntax is deprecated in PHP 7.0 and forward. You will need to change to mysqli_* or PDO.



      You mention in the comments that you "already opted for mysqli", but the syntax provided in your question is a mixed syntax of mysql and mysqli. mysqli takes the database connection as a parameter, while mysql does not.



      Therefore, change your mysql_* to mysqli_*.



      Examples from your question:



      mysql_query($query, $connessione)



      to



      mysqli_query($query, $connessione)



      etc.



      If you're in doubt about what the syntax is for the different mysqli_* functions, then I would suggest looking it up. This thread is a good place to start if you're changing from mysql to mysqli.






      share|improve this answer


























        0












        0








        0







        The problem occurs because the mysql_* syntax is deprecated in PHP 7.0 and forward. You will need to change to mysqli_* or PDO.



        You mention in the comments that you "already opted for mysqli", but the syntax provided in your question is a mixed syntax of mysql and mysqli. mysqli takes the database connection as a parameter, while mysql does not.



        Therefore, change your mysql_* to mysqli_*.



        Examples from your question:



        mysql_query($query, $connessione)



        to



        mysqli_query($query, $connessione)



        etc.



        If you're in doubt about what the syntax is for the different mysqli_* functions, then I would suggest looking it up. This thread is a good place to start if you're changing from mysql to mysqli.






        share|improve this answer













        The problem occurs because the mysql_* syntax is deprecated in PHP 7.0 and forward. You will need to change to mysqli_* or PDO.



        You mention in the comments that you "already opted for mysqli", but the syntax provided in your question is a mixed syntax of mysql and mysqli. mysqli takes the database connection as a parameter, while mysql does not.



        Therefore, change your mysql_* to mysqli_*.



        Examples from your question:



        mysql_query($query, $connessione)



        to



        mysqli_query($query, $connessione)



        etc.



        If you're in doubt about what the syntax is for the different mysqli_* functions, then I would suggest looking it up. This thread is a good place to start if you're changing from mysql to mysqli.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 12:07









        MartinMartin

        8861411




        8861411






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408438%2fmove-script-from-php-5-6-to-php-7%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith