Results 1 to 10 of 11

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    375
    Plugin Contributions
    3

    red flag Need help for fix MySQL to MySQLi Error on old moudles

    Hi,

    I am upgrading a ZC 1.5.1 to ZC 1.5.4

    The ZC 1.5.4 logs see some log like this
    PHP Warning: mysql_query(): Access denied for user 'user'@'localhost' (using password: NO) in /home/user/public_html/zc/admin/shipping_export1.php on line 1194

    PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/user/public_html/zc/admin_xx/shipping_export1.php on line 1195

    PHP Warning: mysql_query(): Access denied for user 'user'@'localhost' (using password: NO) in /home/user/public_html/zc/admin/shipping_export1.php on line 1198

    PHP Warning: mysql_query(): A link to the server could not be established in /home/user/public_html/zc/admin/shipping_export1.php on line 1198

    Yes, yes it is a Export Shipping+Order Information
    but .... since some reason, I need change it to match my need, so above file named shipping_export1.php


    While I google some inform know that from ZC 1.5.3 starting move from MySQL to MySQLi

    And I also see the
    Zen Cart’s database abstraction layer
    https://www.zen-cart.com/wiki/index....ers_-_Database

    But ... not too understand how to fix my self coding

    Here are my coding that can work on ZC 1.5.1, but not the ZC 1.5.4
    where the shipping_export1.php on line 1194 is below "$yu"

    PHP Code:
    <?php
                    $payment_term
    =$module->title;
                    
    $payment_method=(strstr($module->code'paypal') ? 'PayPal' $module->code);
                    
    $yu=mysql_query("SELECT * from required_definitions where payment_method = '".$payment_method."'  ");
                    
    $req=mysql_fetch_array($yu);
                    if(
    $req['payment_method'] != $payment_method)
                    {
                    
    mysql_query("INSERT into required_definitions (payment_method,class,class_name,definition) VALUES ('".$payment_method."','','','')");    
                    }
                    
                  
    ?>

    and after I am read the
    Zen Cart’s database abstraction layer
    https://www.zen-cart.com/wiki/index....ers_-_Database

    I had try change the line 1194 to
    PHP Code:
    $yu=$db->Execute("SELECT * from required_definitions where payment_method = '".$payment_method."'  "); 
    then the logs not show error on line 1194 anymore, but ... I still see error on line 1195, 1198, no example for me as reference, I am lost of idea how to change it using $db->Execute way ..

    Any one can help me fix it? Thank you.

  2. #2
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,532
    Plugin Contributions
    127

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    PHP Code:
    <?php
                    $payment_term
    =$module->title;
                    
    $payment_method=(strstr($module->code'paypal') ? 'PayPal' $module->code);
                    
    $yu=$db->Execute("SELECT * from required_definitions where payment_method = '".$payment_method."'  ");
                    
    $req=$yu->fields['payment_method'];
                    if(
    $req != $payment_method)
                    {
                    
    $db->Execute("INSERT into required_definitions (payment_method,class,class_name,definition) VALUES ('".$payment_method."','','','')");    
                    }
                    
                  
    ?>
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  3. #3
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    Looks like the rest of the code may also need an overhaul, because the table names are also hard coded.

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,532
    Plugin Contributions
    127

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    If it worked before, it means he's not using a prefix. I agree this is not best practice, but there you are.

    One thing @explorer1979 *should* be on the lookout for is missing sanitization of input values, which was common in older modules.
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  5. #5
    Join Date
    Jan 2007
    Posts
    375
    Plugin Contributions
    3

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    design75,

    Hi, thank you of your suggestion, I write this since I using phpmyadmin most time..
    Directly using it SQL tab to write SQL, so if can work I will copy and paste on it.
    And like what I said before, this is my self need custom coding for my shop output some special CSV, not include on original "Export Shipping+Order Information" official ZC module.

  6. #6
    Join Date
    Jan 2007
    Posts
    375
    Plugin Contributions
    3

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    swguy,

    Thank you, your coding work for me.
    But one more question more ....

    I using ZC Build-in Developer Tools try search "->fields"

    See some example using this
    $somereq=$something->fields;

    Do
    PHP Code:
    $req=$yu->fields['payment_method']; 
    can be
    PHP Code:
    $req=$yu->fields;
    if(
    $req['payment_method'] != $payment_method


    this way? if yes, why? or where can find the function define on ZC of this ->filed object?

    Sorry look like a bit more questions, I am still learning PHP, now working on PHP function this learning, for PHP OOP and object I am still a new comer, want to know more ... since I know ZC 1.6 or up will be more OOP way ..

    So, it is time to learning more from this ..

    Thank you of your value time and help.

  7. #7
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,532
    Plugin Contributions
    127

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    Quote Originally Posted by explorer1979 View Post

    I using ZC Build-in Developer Tools try search "->fields"

    See some example using this
    $somereq=$something->fields;

    Do
    PHP Code:
    $req=$yu->fields['payment_method']; 
    can be
    PHP Code:
    $req=$yu->fields;
    if(
    $req['payment_method'] != $payment_method

    This would be different than all the other code you see in Zen Cart. It's really best to keep with the coding standard you see in all the other files.
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  8. #8
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,942
    Plugin Contributions
    96

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    Quote Originally Posted by explorer1979 View Post
    swguy,

    Thank you, your coding work for me.
    But one more question more ....

    I using ZC Build-in Developer Tools try search "->fields"

    See some example using this
    $somereq=$something->fields;

    Do
    PHP Code:
    $req=$yu->fields['payment_method']; 
    can be
    PHP Code:
    $req=$yu->fields;
    if(
    $req['payment_method'] != $payment_method


    this way? if yes, why? or where can find the function define on ZC of this ->filed object?

    Sorry look like a bit more questions, I am still learning PHP, now working on PHP function this learning, for PHP OOP and object I am still a new comer, want to know more ... since I know ZC 1.6 or up will be more OOP way ..

    So, it is time to learning more from this ..

    Thank you of your value time and help.
    When you see the PHP construct $yu->fields within Zen Cart code, there's usually a preceeding call to a $db (database object) function that requests information from the database similar to $yu = $db->Execute ("SELECT <field list> FROM " . TABLE_SOMETHING);

    Each associative array-element of the fields value returned "maps" to an entry in the <field list> of that SQL query.

  9. #9
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    Using the above:
    Code:
    $req=$yu->fields['payment_method'];
    And
    Code:
    $req2=$yu->fields;
    Then:
    Code:
    $req===$req2['payment_method']
    The difference is that $req is a single value, where $req2 is an array of values. So there is a bit of a trade-off and potential need for either of these. It would be a waste of memory and related processing time to store the array if the query returns many values but only one is ever used.

    Also, problems can arise in the code if the array is maintained through a long series of code that could potentially modify one or more keys of the variable. By working with one portion of the total the code can typically be easier to follow and modify without impacting the entire program.

    By using the first method as suggested by swguy, the code tends to be easier to read, to understand, and more importantly to debug.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,532
    Plugin Contributions
    127

    Default Re: Need help for fix MySQL to MySQLi Error on old moudles

    Quote Originally Posted by mc12345678 View Post
    ...
    The difference is that $req is a single value, where $req2 is an array of values. So there is a bit of a trade-off and potential need for either of these. It would be a waste of memory and related processing time to store the array if the query returns many values but only one is ever used.
    This is almost certainly more than the OP wanted to know, but:

    There is no additional cost in memory or processing time for method 2. You have already paid the price for retrieving and storing these variables. To reduce memory and processing time, you could change

    Code:
                    $yu=$db->Execute("SELECT * from required_definitions where payment_method = '".$payment_method."'  ");
    to

    Code:
                    $yu=$db->Execute("SELECT payment_method from required_definitions where payment_method = '".$payment_method."'  ");
    since the field "payment_method" is the only one used.

    That would save the additional overhead of retrieving the additional fields in the required_definitions table.
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

 

 

Similar Threads

  1. v155 Problems with your MySQL (mysqli) support
    By Jacques Smit in forum Installing on a Linux/Unix Server
    Replies: 12
    Last Post: 19 Feb 2024, 09:28 AM
  2. v138a 1064 Error in SQL Syntax - old v.1.3.8 on new MySQL
    By Chasel in forum Installing on a Windows Server
    Replies: 3
    Last Post: 18 Aug 2012, 07:36 PM
  3. MYSQL vs MYSQLi
    By Bad Dingo in forum Installing on a Windows Server
    Replies: 2
    Last Post: 9 Aug 2009, 03:43 AM
  4. HELP! Website reverted to old template...can't fix by myself!
    By eschlosser in forum General Questions
    Replies: 8
    Last Post: 19 Mar 2009, 04:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg