sql access

Discussion in 'Server Operation' started by jbonlinea, Sep 19, 2017.

  1. jbonlinea

    jbonlinea Member

    hi there

    I've been folowing the perfect server with debian 9 and ISPConfig tuto and went through smoothly.
    I set up my vhosts and user, and so. Also I installed php5.6 for a legacy website I still want to keep alive.

    Now I have a vhost running with php5.6, however I can't access to the db using the following code (I know it's outdated, but still works on ubuntu 16.04 with apache 2.4 and mysql as well as a synology disk station with apache 2.4 and mariadb10.

    $database_demo "MyDbName";
    $username_demo "MySqlUser";
    $password_demo "MySqlUserPassword";
    $demo = @mysql_pconnect($hostname_demo$username_demo$password_demo) or trigger_error(mysql_error(),E_USER_ERROR);
    $query_journal "SELECT journal_id, journal_commentaires, journal_simg_url, etat FROM tbl_accueil WHERE etat = 'actif' ORDER BY journal_id DESC";
    $journal mysql_query($query_journal$demo) or die(mysql_error());
    $row_journal mysql_fetch_assoc($journal);
    $totalRows_journal mysql_num_rows($journal);
    Since I couldn't get a connexion I tried to replace the server "localhost" for "localhost:3306", "", and "" but none of these worked.
    Same with root account !

    Pretty frustrated, I tried to install a CMS (spip) but I bump into an error message informing me that php mysql extension wasn't installed.

    ok well my issue is double :
    first I don't use mysql but mariadb
    second, as there are no results to "dpkg --list | grep php5-mysql" and "dpkg --list | grep php7-mysql" thus I realized that I don't have the mysql extension neither for php5 nor php7

    Yet, I have no issue to install my CMS on a other vhost running on php7.

    I thus wonder what should I do ?
    install mysql extention for php5 like this "apt-get install php5-mysql" ?
    or is there a mariadb extention for php5 ?
    or what ?

    I'm kind of stuck, it's my fist server using mariadb, and i would like to avoid to mess with extensions I don't know about.
    Thank's for your help

    Attached Files:

  2. HSorgYves

    HSorgYves Active Member HowtoForge Supporter

    First of all there is no php5 for Debian9, second there is no mysql library for php7. Nevertheless you access your database (mariadb uses the same php library as mysql) through mysqli.
    However to help you, one crutial info is missing: how did you install php5 on Debian9?
  3. jbonlinea

    jbonlinea Member

    ok and ok.
    Also it's good to know that mariadb use the same php library than mysql, I knew the migration was almost flawless, but knowing why and how is great.
    True that, I forgot to mention that I installed php5.6 using this tutorial :How to install PHP 7.x as PHP-FPM & FastCGI for ISPConfig 3.1 with apt on Debian 8 and 9
    Precisely, I first did the step 2 for php7 which was already installed, then moved to step 4 and 5 to install php5.6, and finally I covered the step 2 again to add php5.6 to ISPConfig.

    To test my set up, I created two vhost, respectivelly running php5.6 and php7 and dropped a phpinfo.php file in each web folder, providing me the document attatched in my previous post.


    complementary note : Some month ago I installed a server with ubuntu 16.04 following this tuto and added php5.6 following this other tuto, went trough flawlessly, and the code above worked out of the box to connect to mysql on a vhost running php5.6
    Last edited: Sep 19, 2017
  4. HSorgYves

    HSorgYves Active Member HowtoForge Supporter

    I was wrong to some extend yesterday: the Debian package is called php-mysql which is only there to install php7.0-mysql. This package however includes only the mysqli library for php7, as mysql was being deprecated, check https://packages.debian.org/stretch/amd64/php7.0-mysql/filelist
    You did install php from an external repository. As far as I can see this repository offers a mysql package for php5.6, check https://packages.sury.org/php/pool/main/p/php5.6/
    Try to install it using: apt-get install php5.6-mysql
  5. jbonlinea

    jbonlinea Member

    Yes I knew that the mysql extension is deprecated/not suported/not included anymore since php5.6 and replaced by mysqli : here and here
    But my code above dates back from 2005, and was thus written with mysql in mind, not mysqli yet.
    And yes I added the sury.com repo.

    I was a bit feared of installing php5.6-mysql as I wasn't sure what would actually be installed, mysql, mysqli, mysqlnd, pdo_mysql, and if there might have inconsistencies or conflict.
    It happens that running apt-get install php5.6-mysql, from the sury.com repo, install them all.

    My code is now working perfectly !

    Complementary note 1)
    I've been a bit silly yesterday as I ran "dpkg --list | grep php7-mysql" with no result instead of "dpkg --list | grep php7.0-mysql" indeed showing me results.
    The same goes for "dpkg --list | grep php5-mysql" as I should have been typing "dpkg --list | grep php5.6-mysql", however in this second case both would have returned nothing as php5.6-mysql was indeed not installed yet

    Complementary note 2)
    It might be misleading, but it seems that migrating from mysql to mariadb has nothing to do with the php extension needed, at least on the php side, as you mentionned both use the same; the key is wether your code needs mysql, mysqli or mysqlnd ; as php7 do not include mysql anymore (deprecated as mentionned), my legacy site has to run on php5.6, and it obviously need a php5.6 extension for mysql
  6. HasanGMC

    HasanGMC New Member

    nice, thanks
  7. Nogalmarian

    Nogalmarian New Member

    it seems that migrating from mysql to mariadb has nothing to do with the php extension needed
    Only config.
  8. jbonlinea

    jbonlinea Member

    I'm not absolutly sure about what I'm going to say but , if I'm not totally right, most should be ok.

    Indeed, as
    In PHP5.x, you can use three php extension to acces your db : mysql, mysqli and pdo mysql to connect to your db server, wether it is mysql or mariadb
    In PHP7.x, mysql has been removed so there are two options left : mysqli and mysqlnd, and as above both works with both servers

    Whether you are using mysql, mysqli or mysqlnd depends of your code: for instance in the first post the code is using mysql, see the php documentation here for more details

    So basically migrating from mysql to mariadb may ot not has to do with the extension you use.

    hope this helps
    maybe someone will confirn
    Last edited: Sep 30, 2017
  9. HSorgYves

    HSorgYves Active Member HowtoForge Supporter

    Why can't you connect to mariadb using mysql php extension?
  10. jbonlinea

    jbonlinea Member

    eu ?

    Actually I did some quick research to try to answer you with a bit more of confidence, and it appears that I mixed up few thing in my previous post, up to the point that I'll edit it to avoid to let mistaken explications.

    It's kind of a dumb answer but the compatibility between mysql and mariadb is almost binary (to use mariadb documentation vocabulary), however there my be few surprise, depending of the version you use...
    Last edited: Sep 30, 2017
  11. HSorgYves

    HSorgYves Active Member HowtoForge Supporter

    I was refering to this. Please post a reference, because I think that is wrong.
    AFAIK you can use all 2/3 (depending on the php release) php extensions to connect to either mysql or mariadb. As a consequence, switching from mysql to mariadb (what most distributions did) has no incidence on your server setup.
  12. jbonlinea

    jbonlinea Member

    yes indeed, I edited my previous answer as I was indeed mistacken

Share This Page