IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Problème de connexion à une base de donnée.


Sujet :

PHP & Base de données

  1. #1
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut Problème de connexion à une base de donnée.
    Bonjour.

    Je ne parviens pas à me connecter à ma base de données car les codes que je possède sont obsolètes pour mon serveur distant.Bien qu'en local tout fonctionne sous wamp.
    Les voici:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <?php
        $CFG_HOSTNAME = 'xxxxxxxx';
    	$CFG_USERNAME = 'user';
    	$CFG_PASSWORD = 'passe';
    	$CFG_DATABASE = 'xxxxxxx';
     
    	$mysql = new mysql($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
        $mysql->connect_select(__LINE__,__FILE__);
    ?>
    J'ai commencé à écrire ce code en PDO qui a déjà fait ces preuves sur une autre application:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?php
    try 
    {
      $connection = new PDO("mysql:host=xxxxx;dbname=xxxxxx", user, passe, 
      array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));  
    } 
    catch ( Exception $e ) 
    {
      echo "Connection à MySQL impossible : ", $e->getMessage();
      die();
    }
    ?>
    Mais ne comprenant pas la ligne que voici et qui correspond au code obsolète:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $mysql->connect_select(__LINE__,__FILE__);
    je ne peux donc pas adapter ces anciens codes pour mon serveur.
    Alors j'en appelle à votre aide pour que je puisse mener à bien cette mise à jour.
    Merci d'avance.
    L' ignorance, toujours mène à la servitude.

  2. #2
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Bon, déjà la classe mysql n'existe pas en php natif : tu dois donc avoir quelque part dans ton application une classe mysql qui définit (entre autres) cette fonction connect_select.

    La bonne nouvelle, c'est que ta classe mysql n'est peut-être réellement obsolète, ce sont les fonctions utilisées à l'intérieur qui le sont (enfin probablement) Tu n'as peut-être pas besoin de remplacer ta classe, mais uniquement de modifier les fonctions à l'intérieur (oh joie et félicitée !)

    Donc 1ere étape : trouver la classe mysql dans ton application et nous la montrer pour qu'on puisse analyser tout ça.

    (ça pourrait aussi aider de connaitre aussi la version de PHP sur ton Wamp local et sur le serveur réel)
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  3. #3
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    Voici la fonction recherchée:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    	function connect_select( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		$this->clear_arguments( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->load_arguments($args);
    		}
     
    		$this->connect( );
    		$this->select( );
    	}
    Quand à la version de Wamp que j'utilise la voici:
    2.5
    Avec php 5.5.12

    Pour mon serveur réel:
    Apache 2.2.16
    PHP:5.6.15

    Et voici le message d'erreur qu'il m'est retourné:
    There was a database error. An email has been sent to the system administrator.
    (je ne reçois pas le email indiqué).

    Merci de bien vouloir m'aider.Cette installation est importante pour moi.
    L' ignorance, toujours mène à la servitude.

  4. #4
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Ah ouais... ben en fait, on est pas plus avancé : ta fonction prend les données passées en paramètres (donc ici __LINE__ et __FILE__, autrement dit le numéro de la ligne et le nom du fichier où la fonction est appelée) et les envoie à une fonction load_arguments, puis appelle une fonction connect et une fonction select. Problème : on ne sait pas ce que contiennent ces fonctions.

    Je crois qu'il va falloir que tu nous montres toute la classe mysql.
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  5. #5
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    Alors voici tous les codes du fichier mysql.classe.php auquel tu trouveras en ligne 162 "function connect_select( )" :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    <?php
    /*
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    */
     
    class mysql
    {
        var $linkid;      // MySQL Resource ID
        var $host;        // MySQL Host name
        var $user;        // MySQL Username
        var $pswd;        // MySQL password
        var $db;          // MySQL Database
        var $query;       // MySQL query
        var $query_time;  // Time it took to run the query
        var $pass_query;  // Query passed by argument
        var $result;      // Query result
        var $line;        // Line of query
        var $file;        // File of query
        var $error;       // Any error message encountered while running
        var $log_path;    // The path to the log file
        var $querycount;  // Total number of queries executed since class inception
        var $error_debug; // Allows for error debug output
        var $query_debug; // Allows for output of all queries all the time
        var $super_debug; // Allows output of ALL debugging output
     
     
     
        /* Class constructor.  Initializes the host, user, pswd, db and log fields */
        function mysql($host, $user, $pswd, $db, $log_path = './')
        {
     
            /*#
              #
              # The following was moved to the config file for
              # ease of use by the admin (so they don't have to config
              # multiple files, and only have to edit one),
              # but the original source was left here for those who wish
              # to implement this class in their own creations.
              #
              # to enable, just change  /*#  above to  //*#  and edit settings
              #
              # to disable, change  //*#  above to  /*#
              # and copy-paste this section into your own config file
              #
     
            // BEGIN CONFIG ----------------------
     
            define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
            define ('DB_ERR_LOG_ERRORS'  , true); // (true / false) set to true to log errors in mysql.err file
            define ('DB_ERR_TO'          , 'yourname@yoursite.com'); // set your TO email address
            define ('DB_ERR_SUBJECT'     , 'Query Error'); // don't really need to change this
            define ('DB_ERR_FROM'        , 'yourname@yoursite.com'); // set your FROM email address (can be the same as TO above)
            define ('FILE_PATH_END'      , '/yourscript/'); // the name of the directory containing the script (with wrapping / )
     
            // END CONFIG ------------------------
     
              #
              # end of config section removal
              #
              #*/
     
            $this->host = $host;
            $this->user = $user;
            $this->pswd = $pswd;
            $this->db   = $db;
            $this->log_path = $log_path;
     
            // each of these can be set independently as needed
            $this->error_debug = false; // set to true for output of errors
            $this->query_debug = false; // set to true for output of every query
            $this->super_debug = false; // set to true for other debugging output (like passed query arguments, etc.)
     
            // make sure the log path ends with /
            if (strrpos($this->log_path,'/') != (strlen($this->log_path) - 1))
            {
                $this->log_path .= '/';
            }
        }
     
     
     
        /* Connect to the MySQL database server */
        function connect( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->load_arguments($args);
            }
     
            $this->linkid = @mysql_connect($this->host, $this->user, $this->pswd);
     
            if ( ! $this->linkid)
            {
                $this->error = mysql_errno( ).': '.mysql_error( );
                $this->error_report( );
     
                if ($this->error_debug)
                {
                    echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
                }
                else
                {
                    die('There was a database error. An email has been sent to the system administrator.');
                }
            }
        }
     
     
     
        /* Selects the MySQL Database */
        function select( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->load_arguments($args);
            }
     
            if ( ! @mysql_select_db($this->db, $this->linkid))
            {
                $this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
                $this->error_report( );
     
                if ($this->error_debug)
                {
                    echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
                }
                else
                {
                    die('There was a database error. An email has been sent to the system administrator.');
                }
            }
        }
     
     
     
        /* Connects to the server AND selects the default database in one function */
        function connect_select( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            $this->clear_arguments( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->load_arguments($args);
            }
     
            $this->connect( );
            $this->select( );
        }
     
     
     
        /* Execute Database Query */
        function query( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->clear_arguments( ); // don't clear unless we have new
                $this->load_arguments($args);
     
                if (false !== $this->pass_query)
                {
                    $this->query = $this->pass_query;
                }
            }
     
            if ($this->super_debug)
            {
                echo 'QUERY ';
                echo '<pre>';
                print_r($this->get_arguments( ));
                echo '</pre>';
            }
     
            $done = true; // innocent until proven guilty
     
            // start time logging
            $time = microtime_float( );
            $this->result = @mysql_query($this->query, $this->linkid);
            $this->query_time = microtime_float( ) - $time;
     
            if ($this->query_debug)
            {
                $this->query = trim(preg_replace('/\\s+/', ' ', $this->query));
                echo "<div style='background:white;color:black;'><br />{$this->query} - <strong>Aff(".$this->affected_rows( ).") - {$this->file_name}: {$this->line}</strong></div>";
            }
     
            if ( ! $this->result)
            {
                $this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
                $this->error_report( );
     
                if ($this->error_debug)
                {
                    echo "<div style='background:#900;color:white;'>There was an error in your query in {$this->file_name} on line {$this->line}: ERROR - {$this->error}<br />Query: {$this->query}</div>";
                    print_r(debug_backtrace( ));
                }
                else
                {
                    $this->error = 'There was a database error. An email has been sent to the system administrator.';
                }
     
                $done = false;
            }
     
            if ($done)
            {
                $this->querycount++;
                return $this->result;
            }
     
            return false;
        }
     
     
     
        /* Determine total rows affected by query */
        function affected_rows( )
        {
            $count = @mysql_affected_rows($this->linkid);
            return $count;
        }
     
     
     
        /* Determine total rows returned by query */
        function num_rows( )
        {
            $count = @mysql_num_rows($this->result);
     
            if ( ! $count)
            {
                return 0;
            }
     
            return $count;
        }
     
     
        /** public function insert
         *      Insert the associative data array into the table.
         *          $data['field_name'] = value
         *          $data['field_name2'] = value2
         *      If the field name has a trailing space: $data['field_name ']
         *      then the query will insert the data with no sanitation
         *      or wrapping quotes (good for function calls, like NOW( )).
         *
         * @param string table name
         * @param array associative data array
         * @param string [optional] where clause (for updates)
         * @param bool [optional] whether or not we should replace values (true / false)
         * @action execute a mysql query
         * @return int insert id for row
         */
        function insert($table, $data_array, $where = '', $replace = false)
        {
            $where = trim($where);
            $replace = (bool) $replace;
     
            if ('' == $where) {
                $query  = (false == $replace) ? ' INSERT ' : ' REPLACE ';
                $query .= ' INTO ';
            }
            else {
                $query = ' UPDATE ';
            }
     
            $query .= '`'.$table.'`';
     
            if ( ! is_array($data_array)) {
                throw new MySQLException(__METHOD__.': Trying to insert non-array data');
            }
            else {
                $query .= ' SET ';
                foreach ($data_array as $field => $value) {
                    if (is_null($value)) {
                        $query .=  " `{$field}` = NULL , ";
                    }
                    elseif (' ' == substr($field, -1, 1)) { // i picked a trailing space because it's an illegal field name in MySQL
                        $field = trim($field);
                        $query .= " `{$field}` = {$value} , ";
                    }
                    else {
                        $query .= " `{$field}` = '".sani($value)."' , ";
                    }
                }
     
                $query = substr($query, 0, -2).' '; // remove the last comma (but preserve those spaces)
            }
     
            $query .= ' '.$where.' ';
            $this->query = $query;
            $return = $this->query( );
     
            if ('' == $where) {
                return $this->fetch_insert_id( );
            }
            else {
                return $return;
            }
        }
     
     
        /** public function multi_insert
         *      Insert the array of associative data arrays into the table.
         *          $data[0]['field_name'] = value
         *          $data[0]['field_name2'] = value2
         *          $data[0]['DBWHERE'] = where clause [optional]
         *          $data[1]['field_name'] = value
         *          $data[1]['field_name2'] = value2
         *          $data[1]['DBWHERE'] = where clause [optional]
         *
         * @param string table name
         * @param array associative data array
         * @param bool [optional] whether or not we should replace values (true / false)
         * @action execute multiple mysql queries
         * @return array insert ids for rows (with original keys preserved)
         */
        function multi_insert($table, $data_array, $replace = false)
        {
            if ( ! is_array($data_array)) {
                throw new MySQLException(__METHOD__.': Trying to multi-insert non-array data');
            }
            else {
                $result = array( );
     
                foreach ($data_array as $key => $row) {
                    $where = (isset($row['DBWHERE'])) ? $row['DBWHERE'] : '';
                    unset($row['DBWHERE']);
                    $result[$key] = $this->insert($table, $row, $where, $replace);
                }
            }
     
            return $result;
        }
     
     
        /** public function delete
         *      Delete the row from the table
         *
         * @param string table name
         * @param string where clause
         * @action execute a mysql query
         * @return result
         */
        function delete($table, $where)
        {
            $query = "
                DELETE
                FROM `{$table}`
                {$where}
            ";
     
            $this->query = $query;
     
            try {
                return $this->query( );
            }
            catch (MySQLException $e) {
                throw $e;
            }
        }
     
     
        /** public function multi_delete
         *      Delete the array of data from the table.
         *          $table[0] = table name
         *          $table[1] = table name
         *
         *          $where[0] = where clause
         *          $where[1] = where clause
         *
         *      If recursive is true, all combinations of table name
         *      and where clauses will be executed.
         *
         *      If only one table name is set, that table will
         *      be used for all of the queries, looping through
         *      the where array
         *
         *      If only one where clause is set, that where clause
         *      will be used for all of the queries, looping through
         *      the table array
         *
         * @param mixed table name array or single string
         * @param mixed where clause array or single string
         * @param bool optional recursive (default false)
         * @action execute multiple mysql queries
         * @return array results
         */
        function multi_delete($table_array, $where_array, $recursive = false)
        {
            if ( ! is_array($table_array)) {
                $recursive = false;
                $table_array = (array) $table_array;
            }
     
            if ( ! is_array($where_array)) {
                $recursive = false;
                $where_array = (array) $where_array;
            }
     
            if ($recursive) {
                foreach ($table_array as $table) {
                    foreach ($where_array as $where) {
                        $result[] = $this->delete($table, $where);
                    }
                }
            }
            else {
                if (count($table_array) == count($where_array)) {
                    for ($i = 0, $count = count($table_array); $i < $count; ++$i) {
                        $result[] = $this->delete($table_array[$i], $where_array[$i]);
                    }
                }
                elseif (1 == count($table_array)) {
                    $table = $table_array[0];
                    foreach ($where_array as $where) {
                        $result[] = $this->delete($table, $where);
                    }
                }
                elseif (1 == count($where_array)) {
                    $where = $where_array[0];
                    foreach ($table_array as $table) {
                        $result[] = $this->delete($table, $where);
                    }
                }
                else {
                    throw new MySQLException(__METHOD__.': Trying to multi-delete with incompatible array sizes');
                }
            }
     
            return $result;
        }
     
     
     
        /* Return query result row as an object */
        function fetch_object( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->clear_arguments( );
                $this->load_arguments($args);
            }
     
            if ($this->super_debug)
            {
                echo 'FETCH_OBJECT ';
                echo '<pre>';
                print_r($this->get_arguments( ));
                echo '</pre>';
            }
     
            if (false !== $this->pass_query)
            {
                $this->query = $this->pass_query;
                $this->query( );
            }
     
            $row = @mysql_fetch_object($this->result);
            return $row;
        }
     
     
     
        /* Return query result row as an indexed array */
        function fetch_row( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->clear_arguments( );
                $this->load_arguments($args);
            }
     
            if ($this->super_debug)
            {
                echo 'FETCH_ROW ';
                echo '<pre>';
                print_r($this->get_arguments( ));
                echo '</pre>';
            }
     
            if (false !== $this->pass_query)
            {
                $this->query = $this->pass_query;
                $this->query( );
            }
     
            $row = @mysql_fetch_row($this->result);
            return $row;
        }
     
     
     
        /* Return query result row as an associative array */
        function fetch_assoc( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->clear_arguments( );
                $this->load_arguments($args);
            }
     
            if ($this->super_debug)
            {
                echo 'FETCH_ASSOC ';
                echo '<pre>';
                print_r($this->get_arguments( ));
                echo '</pre>';
            }
     
            if (false !== $this->pass_query)
            {
                $this->query = $this->pass_query;
                $this->query( );
            }
     
            $row = @mysql_fetch_assoc($this->result);
            return $row;
        }
     
     
     
        /* Return query result row as an associative array and an indexed array */
        function fetch_both( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->clear_arguments( );
                $this->load_arguments($args);
            }
     
            if ($this->super_debug)
            {
                echo 'FETCH_BOTH ';
                echo '<pre>';
                print_r($this->get_arguments( ));
                echo '</pre>';
            }
     
            if (false !== $this->pass_query)
            {
                $this->query = $this->pass_query;
                $this->query( );
            }
     
            $row = @mysql_fetch_array($this->result, MYSQL_BOTH);
            return $row;
        }
     
     
     
        /* Return query result as an array of arrays */
        function fetch_array( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->clear_arguments( );
                $this->load_arguments($args);
            }
     
            if ($this->super_debug)
            {
                echo 'FETCH_ARRAY ';
                echo '<pre>';
                print_r($this->get_arguments( ));
                echo '</pre>';
            }
     
            if (false !== $this->pass_query)
            {
                $this->query = $this->pass_query;
                $this->query( );
            }
     
            $arr = array( );
            while ($row = @mysql_fetch_array($this->result))
            {
                $arr[] = $row;
            }
     
            return $arr;
        }
     
     
     
        /* Return query result as an array of single values */
        function fetch_value_array( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->clear_arguments( );
                $this->load_arguments($args);
            }
     
            if ($this->super_debug)
            {
                echo 'FETCH_VALUE_ARRAY ';
                echo '<pre>';
                print_r($this->get_arguments( ));
                echo '</pre>';
            }
     
            if (false !== $this->pass_query)
            {
                $this->query = $this->pass_query;
                $this->query( );
            }
     
            $arr = array( );
            while ($row = @mysql_fetch_row($this->result))
            {
                $arr[] = $row[0];
            }
     
            return $arr;
        }
     
     
     
        /* Return single query result value */
        function fetch_value( )
        {
            $num_args = func_num_args( );
            $args     = func_get_args( );
     
            // get the arguments, if any
            if (0 != $num_args)
            {
                $this->clear_arguments( );
                $this->load_arguments($args);
            }
     
            if ($this->super_debug)
            {
                echo 'FETCH_VALUE ';
                echo '<pre>';
                print_r($this->get_arguments( ));
                echo '</pre>';
            }
     
            if (false !== $this->pass_query)
            {
                $this->query = $this->pass_query;
                $this->query( );
            }
     
            $row = @mysql_fetch_row($this->result);
            return $row[0];
        }
     
     
     
        /* Return the total number of queries executed during
             the lifetime of this object                         */
        function num_queries( )
        {
            return $this->querycount;
        }
     
     
     
        /* get the id for the previous INSERT command */
        function fetch_insert_id( )
        {
            return @mysql_insert_id($this->linkid);
        }
     
     
     
        /* get the errors, if any */
        function fetch_error( )
        {
            return $this->error;
        }
     
     
     
        /* report the errors to the admin */
        function error_report( )
        {
            // generate an error report and then act according to configuration
            $error_report  = "An error has been generated by the server.\nFollowing is the debug information:\n\n";
            $error_report .= "   *  File: {$this->file_name}\n";
            $error_report .= "   *  Line: {$this->line}\n";
            $error_report .= "   * Error: {$this->error}\n";
     
            $error_report_short = "\n" . date('Y-m-d H:i:s') . " Error in {$this->file_name} on line {$this->line}: ERROR - {$this->error}";
     
            // if a database query caused the error, show the query
            if ('' != $this->query)
            {
                $error_report .= "   * Query: {$this->query}\n";
                $error_report_short .= " [sql={$this->query}]";
            }
     
            // send the error as email if set
            if (DB_ERR_EMAIL_ERRORS)
            {
                mail(DB_ERR_TO, trim(DB_ERR_SUBJECT), $error_report."\n\n".safe_var_export(debug_backtrace( ))."\n\n\$GLOBALS = ".safe_var_export($GLOBALS), 'From: '.DB_ERR_FROM."\r\n");
            }
     
            // log the error (remove line breaks and multiple concurrent spaces)
            $this->logger(trim(preg_replace('/\\s+/', ' ', $error_report_short))."\n");
        }
     
     
     
        /* log any errors */
        function logger($report)
        {
            if (DB_ERR_LOG_ERRORS)
            {
                $log = $this->log_path . "mysql.err";
                $fp = fopen($log,'a+');
                fwrite($fp,$report);
                @chmod($log, 0777);
                fclose($fp);
            }
        }
     
     
     
        /* extract the arguments */
        function load_arguments($args)
        {
            foreach ($args as $arg)
            {
                if ($this->super_debug)
                {
                    echo '<hr />arg = (';
                    echo stripslashes(var_export($arg, true)).') - ';
                    echo 'is_line('.var_export(is_int($arg), true).') ';
                    echo 'is_file('.var_export(('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg)), true).') ';
                    echo 'is_database('.var_export(is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' ')), true).') ';
                    echo 'is_query('.var_export(0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg), true).') --- ';
                }
     
                if (is_int($arg)) // it's an integer
                {
                    if ($this->super_debug) echo 'LINE - ';
                    $this->line = $arg;
                    if ($this->super_debug) echo $this->line;
                }
                elseif (('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg))) // the string begins with '/' or a drive letter
                {
                    if ($this->super_debug) echo 'FILE - ';
                    $this->file_name = substr($arg, strpos($arg, FILE_PATH_END));
                    if ($this->super_debug) echo $this->file_name;
                }
                elseif (is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' '))) // there are no spaces
                {
                    if ($this->super_debug) echo 'DATABASE - ';
                    $this->db = $arg;
                    if ($this->super_debug) echo $this->db;
                }
                elseif (0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg)) // it begins with a query word
                {
                    if ($this->super_debug) echo 'QUERY - ';
                    $this->pass_query = $arg;
                    if ($this->super_debug) echo $this->pass_query;
                }
                else
                {
                    if ($this->super_debug) echo 'UNKNOWN - ';
                    $arg_dump = var_export($arg, true);
                    $this->error = 'Unknown argument found: ' . $arg_dump;
                    if ($this->super_debug) echo $this->error;
                }
            }
     
            // wait until after all arguments are entered before outputting error
            // because the error may happen on the first argument and the other
            // arguments have important error report data (it's what they're for)
            if ('Unknown argument' == substr((string) $this->error, 0, 16))
            {
                $this->error_report( );
            }
     
            if ($this->super_debug) {echo'<pre>';print_r($this->get_arguments( ));echo'</pre>';}
        }
     
     
     
        /* clear the arguments */
        function clear_arguments( )
        {
            // don't clear query or db as we may use them later
            $this->line = false;
            $this->file_name = false;
            $this->error = false;
            $this->pass_query = false;
        }
     
     
     
        /* return the arguments */
        function get_arguments( )
        {
            $args['line'] = $this->line;
            $args['file'] = $this->file_name;
            $args['error'] = $this->error;
            $args['query'] = $this->pass_query;
     
            return $args;
        }
     
    } // end of mysql class
     
     
     
    /*
     +---------------------------------------------------------------------------
     |   > Extra SQL Functions
     +---------------------------------------------------------------------------
    */
     
     
    /* escape the data before it gets queried into the database */
    function sani($data)
    {
        if (is_array($data))
        {
            return array_map('sani', $data);
        }
        else
        {
            if (get_magic_quotes_gpc( ))
            {
                $data = stripslashes($data);
            }
     
    #    $data = htmlentities($data, ENT_NOQUOTES); // convert html to &html;
     
            if (function_exists('mysql_real_escape_string'))
            {
                $data = mysql_real_escape_string($data); // php 4.3.0+
            }
            else
            {
                $data = mysql_escape_string($data); // php 4.0+
            }
     
            return $data;
        }
    }
     
     
    if ( ! function_exists('microtime_float'))
    {
        function microtime_float( )
        {
            list($usec, $sec) = explode(' ', microtime( ));
            return ((float)$usec + (float)$sec);
        }
    }
     
     
    function safe_var_export($var)
    {
        if ( ! is_array($var))
        {
            return var_export($var, true);
        }
     
        foreach ($var as $key => $data)
        {
            if (('GLOBALS' == $key) || ($data == $var))
            {
                $var[$key] = 'RECURSION';
                continue;
            }
        }
     
        return var_export($var, true);
    }
    Toutes les classes y sont donc.

    La fonction Connect se trouve en ligne 100.
    La fonction Select se trouve en ligne 132
    La fonction load_arguments se trouve en ligne 781
    L' ignorance, toujours mène à la servitude.

  6. #6
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Bon grosso modo, ce que fait ta classe, c'est emballer chaque fonction mysql_xxxx dans une fonction avec plein de logs (notamment via la fonction load_arguments) et des gestions d'erreurs (avec envoi de mail).
    Donc ce qu'il faut faire pour adapter la classe, c'est identifier chaque fonction mysql_xxxx et voir si elle peut être remplacée par quelque chose en PDO.
    L'avantage serait de conserver les logs et tout ce qui va avec. L'inconvénient, c'est que la classe n'est absolument pas conçue pour les requêtes préparées, ce qui est quand même *la* fonctionnalité la plus utile de PDO à mon sens.

    Donc si tu n'utilises pas les logs et autres envois de mail de cette classe, le plus simple est peut-être de rester sur ta 1ere idée et de tout remplacer par des appels PDO directs.
    Pour revenir à ta question initiale, ces deux lignes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $mysql = new mysql($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
    $mysql->connect_select(__LINE__,__FILE__);
    correspondent à l'initialisation de la classe (1ere ligne) et la connexion au serveur et sélection de la base de données (2e ligne). Ce qui peut être entièrement remplacé par l'appel au constructeur de PDO (qui fait à la fois la connexion et la sélection de la base) que tu as écrit dans ton 1er message.
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  7. #7
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    Oui.Je vois déjà à la ligne 111 de la fonction connect que @mysql_connect est incompatible à mon avis avec PDO.
    Mais le problème pour moi est qu'il me faudra beaucoup de recherche pour modifier cette ligne afin de l'adapter à PDO.
    Sinon cette ligne ci dessous peut rester ainsi si j'utilise PDO?:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $mysql->connect_select(__LINE__,__FILE__);
    pour l'adapter ainsi:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    try 
    {
      $mysql = new PDO("mysql:host=xxxxx;dbname=xxxxxx", user, passe, 
      array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));  
    } 
    catch ( Exception $e ) 
    {
      echo "Connection à MySQL impossible : ", $e->getMessage();
      die();
    $mysql->connect_select(__LINE__,__FILE__);
    }
    Dit moi si je me trompe déjà ce niveau.
    L' ignorance, toujours mène à la servitude.

  8. #8
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Non, si tu utilises PDO directement, tu n'as plus besoin de la fonction select_connect :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    try 
    {
      $cnx= new PDO("mysql:host=xxxxx;dbname=xxxxxx", user, passe, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));  
    } 
    catch ( Exception $e ) 
    {
      echo "Connection à MySQL impossible : ", $e->getMessage();
      die();
    }
    // suite de l'utilisation
    Autre possibilité : utiliser mysqli.
    Personnellement je n'aime pas mysqli, parce que c'est un croisement bizarre entre l'API mysql et PDO, mais ça a ses avantages. Notamment dans ton cas : mysqli en mode procédural ressemble énormément à mysql (c'est fait exprès en fait), avec essentiellement des différences dans les paramètres.
    Par exemple, ta fonction connect deviendrait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    function connect( )
    {
        $num_args = func_num_args( );
        $args     = func_get_args( );
     
        // get the arguments, if any
        if (0 != $num_args)
        {
            $this->load_arguments($args);
        }
     
        $this->linkid = @mysqli_connect($this->host, $this->user, $this->pswd);
     
        if (mysqli_connect_error())
        {
            $this->error = mysqli_connect_errno( ).': '.mysqli_connect_error( );
            $this->error_report( );
     
            if ($this->error_debug)
            {
                echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
            }
            else
            {
                die('There was a database error. An email has been sent to the system administrator.');
            }
        }
    }
    et ta fonction select :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    function select( )
    {
        $num_args = func_num_args( );
        $args     = func_get_args( );
     
        // get the arguments, if any
        if (0 != $num_args)
        {
            $this->load_arguments($args);
        }
     
        if ( ! @mysqli_select_db($this->linkid, $this->db ))
        {
            $this->error = mysqli_errno($this->linkid).': '.mysqli_error($this->linkid);
            $this->error_report( );
     
            if ($this->error_debug)
            {
                echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
            }
            else
            {
                die('There was a database error. An email has been sent to the system administrator.');
            }
        }
    }
    ça aura l'avantage de nécessiter très peu de modifications.
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  9. #9
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    Merci déjà pour ce que tu as fait pour moi jusqu' à présent.
    Cependant il y de nouveau un message d'erreur que voici:
    Connection à MySQL impossible : SQLSTATE[HY000] [1045] Access denied for user 'jeuxXXXXXXXXXXXXfr'@'11.XXX.XX.45' (using password: YES)

    Si tu veux bien vérifier si je n'ai pas fait d'erreur sur les lignes 130 à 157 et 188 à 213 pour le fichier mysql.class.php. ci dessous dont j'ai effectué un copier/coller pour ces codes en question:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    <?php
    /*
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    */
     
    class mysql
    {
    	var $linkid;      // MySQL Resource ID
    	var $host;        // MySQL Host name
    	var $user;        // MySQL Username
    	var $pswd;        // MySQL password
    	var $db;          // MySQL Database
    	var $query;       // MySQL query
    	var $query_time;  // Time it took to run the query
    	var $pass_query;  // Query passed by argument
    	var $result;      // Query result
    	var $line;        // Line of query
    	var $file;        // File of query
    	var $error;       // Any error message encountered while running
    	var $log_path;    // The path to the log file
    	var $querycount;  // Total number of queries executed since class inception
    	var $error_debug; // Allows for error debug output
    	var $query_debug; // Allows for output of all queries all the time
    	var $super_debug; // Allows output of ALL debugging output
     
     
     
    	/* Class constructor.  Initializes the host, user, pswd, db and log fields */
    	function mysql($host, $user, $pswd, $db, $log_path = './')
    	{
     
    		/*#
    		  #
    		  # The following was moved to the config file for
    		  # ease of use by the admin (so they don't have to config
    		  # multiple files, and only have to edit one),
    		  # but the original source was left here for those who wish
    		  # to implement this class in their own creations.
    		  #
    		  # to enable, just change  /*#  above to  //*#  and edit settings
    		  #
    		  # to disable, change  //*#  above to  /*#
    		  # and copy-paste this section into your own config file
    		  #
    
    		// BEGIN CONFIG ----------------------
    
    		define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
    		define ('DB_ERR_LOG_ERRORS'  , true); // (true / false) set to true to log errors in mysql.err file
    		define ('DB_ERR_TO'          , 'yourname@yoursite.com'); // set your TO email address
    		define ('DB_ERR_SUBJECT'     , 'Query Error'); // don't really need to change this
    		define ('DB_ERR_FROM'        , 'yourname@yoursite.com'); // set your FROM email address (can be the same as TO above)
    		define ('FILE_PATH_END'      , '/yourscript/'); // the name of the directory containing the script (with wrapping / )
    
    		// END CONFIG ------------------------
    
    		  #
    		  # end of config section removal
    		  #
    		  #*/
     
    		$this->host = $host;
    		$this->user = $user;
    		$this->pswd = $pswd;
    		$this->db   = $db;
    		$this->log_path = $log_path;
     
    		// each of these can be set independently as needed
    		$this->error_debug = false; // set to true for output of errors
    		$this->query_debug = false; // set to true for output of every query
    		$this->super_debug = false; // set to true for other debugging output (like passed query arguments, etc.)
     
    		// make sure the log path ends with /
    		if (strrpos($this->log_path,'/') != (strlen($this->log_path) - 1))
    		{
    			$this->log_path .= '/';
    		}
    	}
     
     
     
    	/* Connect to the MySQL database server */
    	/*function connect( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
    
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->load_arguments($args);
    		}
    
    		//$this->linkid = mysql_connect($this->host, $this->user, $this->pswd);
    		$this->linkid =  mysqli_query ($this->host, $this->user, $this->pswd);
    
    		if ( ! $this->linkid)
    		{
    			$this->error = mysql_errno( ).': '.mysql_error( );
    			$this->error_report( );
    
    			if ($this->error_debug)
    			{
    				echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
    			}
    			else
    			{
    				die('There was a database error. An email has been sent to the system administrator.');
    			}
    		}
    	}
    */
    function connect( )
    {
        $num_args = func_num_args( );
        $args     = func_get_args( );
     
        // get the arguments, if any
        if (0 != $num_args)
        {
            $this->load_arguments($args);
        }
     
        $this->linkid = @mysqli_connect($this->host, $this->user, $this->pswd);
     
        if (mysqli_connect_error())
        {
            $this->error = mysqli_connect_errno( ).': '.mysqli_connect_error( );
            $this->error_report( );
     
            if ($this->error_debug)
            {
                echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
            }
            else
            {
                die('There was a database error. An email has been sent to the system administrator.');
            }
        }
    }
     
     
    	/* Selects the MySQL Database */
    	/*function select( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
    
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->load_arguments($args);
    		}
    
    		if ( ! @mysql_select_db($this->db, $this->linkid))
    		{
    			$this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
    			$this->error_report( );
    
    			if ($this->error_debug)
    			{
    				echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
    			}
    			else
    			{
    				die('There was a database error. An email has been sent to the system administrator.');
    			}
    		}
    	}
    */
    function select( )
    {
        $num_args = func_num_args( );
        $args     = func_get_args( );
     
        // get the arguments, if any
        if (0 != $num_args)
        {
            $this->load_arguments($args);
        }
     
        if ( ! @mysqli_select_db($this->linkid, $this->db ))
        {
            $this->error = mysqli_errno($this->linkid).': '.mysqli_error($this->linkid);
            $this->error_report( );
     
            if ($this->error_debug)
            {
                echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
            }
            else
            {
                die('There was a database error. An email has been sent to the system administrator.');
            }
        }
    }
     
     
    	/* Connects to the server AND selects the default database in one function */
    	function connect_select( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		$this->clear_arguments( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->load_arguments($args);
    		}
     
    		$this->connect( );
    		$this->select( );
    	}
     
     
     
    	/* Execute Database Query */
    	function query( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( ); // don't clear unless we have new
    			$this->load_arguments($args);
     
    			if (false !== $this->pass_query)
    			{
    				$this->query = $this->pass_query;
    			}
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'QUERY ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		$done = true; // innocent until proven guilty
     
    		// start time logging
    		$time = microtime_float( );
    		$this->result = @mysql_query($this->query, $this->linkid);
    		$this->query_time = microtime_float( ) - $time;
     
    		if ($this->query_debug)
    		{
    			$this->query = trim(preg_replace('/\\s+/', ' ', $this->query));
    			echo "<div style='background:white;color:black;'><br />{$this->query} - <strong>Aff(".$this->affected_rows( ).") - {$this->file_name}: {$this->line}</strong></div>";
    		}
     
    		if ( ! $this->result)
    		{
    			$this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
    			$this->error_report( );
     
    			if ($this->error_debug)
    			{
    				echo "<div style='background:#900;color:white;'>There was an error in your query in {$this->file_name} on line {$this->line}: ERROR - {$this->error}<br />Query: {$this->query}</div>";
    				print_r(debug_backtrace( ));
    			}
    			else
    			{
    				$this->error = 'There was a database error. An email has been sent to the system administrator.';
    			}
     
    			$done = false;
    		}
     
    		if ($done)
    		{
    			$this->querycount++;
    			return $this->result;
    		}
     
    		return false;
    	}
     
     
     
    	/* Determine total rows affected by query */
    	function affected_rows( )
    	{
    		$count = @mysql_affected_rows($this->linkid);
    		return $count;
    	}
     
     
     
    	/* Determine total rows returned by query */
    	function num_rows( )
    	{
    		$count = @mysql_num_rows($this->result);
     
    		if ( ! $count)
    		{
    			return 0;
    		}
     
    		return $count;
    	}
     
     
    	/** public function insert
    	 *		Insert the associative data array into the table.
    	 *			$data['field_name'] = value
    	 *			$data['field_name2'] = value2
    	 *		If the field name has a trailing space: $data['field_name ']
    	 *		then the query will insert the data with no sanitation
    	 *		or wrapping quotes (good for function calls, like NOW( )).
    	 *
    	 * @param string table name
    	 * @param array associative data array
    	 * @param string [optional] where clause (for updates)
    	 * @param bool [optional] whether or not we should replace values (true / false)
    	 * @action execute a mysql query
    	 * @return int insert id for row
    	 */
    	function insert($table, $data_array, $where = '', $replace = false)
    	{
    		$where = trim($where);
    		$replace = (bool) $replace;
     
    		if ('' == $where) {
    			$query  = (false == $replace) ? ' INSERT ' : ' REPLACE ';
    			$query .= ' INTO ';
    		}
    		else {
    			$query = ' UPDATE ';
    		}
     
    		$query .= '`'.$table.'`';
     
    		if ( ! is_array($data_array)) {
    			throw new MySQLException(__METHOD__.': Trying to insert non-array data');
    		}
    		else {
    			$query .= ' SET ';
    			foreach ($data_array as $field => $value) {
    				if (is_null($value)) {
    					$query .=  " `{$field}` = NULL , ";
    				}
    				elseif (' ' == substr($field, -1, 1)) { // i picked a trailing space because it's an illegal field name in MySQL
    					$field = trim($field);
    					$query .= " `{$field}` = {$value} , ";
    				}
    				else {
    					$query .= " `{$field}` = '".sani($value)."' , ";
    				}
    			}
     
    			$query = substr($query, 0, -2).' '; // remove the last comma (but preserve those spaces)
    		}
     
    		$query .= ' '.$where.' ';
    		$this->query = $query;
    		$return = $this->query( );
     
    		if ('' == $where) {
    			return $this->fetch_insert_id( );
    		}
    		else {
    			return $return;
    		}
    	}
     
     
    	/** public function multi_insert
    	 *		Insert the array of associative data arrays into the table.
    	 *			$data[0]['field_name'] = value
    	 *			$data[0]['field_name2'] = value2
    	 *			$data[0]['DBWHERE'] = where clause [optional]
    	 *			$data[1]['field_name'] = value
    	 *			$data[1]['field_name2'] = value2
    	 *			$data[1]['DBWHERE'] = where clause [optional]
    	 *
    	 * @param string table name
    	 * @param array associative data array
    	 * @param bool [optional] whether or not we should replace values (true / false)
    	 * @action execute multiple mysql queries
    	 * @return array insert ids for rows (with original keys preserved)
    	 */
    	function multi_insert($table, $data_array, $replace = false)
    	{
    		if ( ! is_array($data_array)) {
    			throw new MySQLException(__METHOD__.': Trying to multi-insert non-array data');
    		}
    		else {
    			$result = array( );
     
    			foreach ($data_array as $key => $row) {
    				$where = (isset($row['DBWHERE'])) ? $row['DBWHERE'] : '';
    				unset($row['DBWHERE']);
    				$result[$key] = $this->insert($table, $row, $where, $replace);
    			}
    		}
     
    		return $result;
    	}
     
     
    	/** public function delete
    	 *		Delete the row from the table
    	 *
    	 * @param string table name
    	 * @param string where clause
    	 * @action execute a mysql query
    	 * @return result
    	 */
    	function delete($table, $where)
    	{
    		$query = "
    			DELETE
    			FROM `{$table}`
    			{$where}
    		";
     
    		$this->query = $query;
     
    		try {
    			return $this->query( );
    		}
    		catch (MySQLException $e) {
    			throw $e;
    		}
    	}
     
     
    	/** public function multi_delete
    	 *		Delete the array of data from the table.
    	 *			$table[0] = table name
    	 *			$table[1] = table name
    	 *
    	 *			$where[0] = where clause
    	 *			$where[1] = where clause
    	 *
    	 *		If recursive is true, all combinations of table name
    	 *		and where clauses will be executed.
    	 *
    	 *		If only one table name is set, that table will
    	 *		be used for all of the queries, looping through
    	 *		the where array
    	 *
    	 *		If only one where clause is set, that where clause
    	 *		will be used for all of the queries, looping through
    	 *		the table array
    	 *
    	 * @param mixed table name array or single string
    	 * @param mixed where clause array or single string
    	 * @param bool optional recursive (default false)
    	 * @action execute multiple mysql queries
    	 * @return array results
    	 */
    	function multi_delete($table_array, $where_array, $recursive = false)
    	{
    		if ( ! is_array($table_array)) {
    			$recursive = false;
    			$table_array = (array) $table_array;
    		}
     
    		if ( ! is_array($where_array)) {
    			$recursive = false;
    			$where_array = (array) $where_array;
    		}
     
    		if ($recursive) {
    			foreach ($table_array as $table) {
    				foreach ($where_array as $where) {
    					$result[] = $this->delete($table, $where);
    				}
    			}
    		}
    		else {
    			if (count($table_array) == count($where_array)) {
    				for ($i = 0, $count = count($table_array); $i < $count; ++$i) {
    					$result[] = $this->delete($table_array[$i], $where_array[$i]);
    				}
    			}
    			elseif (1 == count($table_array)) {
    				$table = $table_array[0];
    				foreach ($where_array as $where) {
    					$result[] = $this->delete($table, $where);
    				}
    			}
    			elseif (1 == count($where_array)) {
    				$where = $where_array[0];
    				foreach ($table_array as $table) {
    					$result[] = $this->delete($table, $where);
    				}
    			}
    			else {
    				throw new MySQLException(__METHOD__.': Trying to multi-delete with incompatible array sizes');
    			}
    		}
     
    		return $result;
    	}
     
     
     
    	/* Return query result row as an object */
    	function fetch_object( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_OBJECT ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_object($this->result);
    		return $row;
    	}
     
     
     
    	/* Return query result row as an indexed array */
    	function fetch_row( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_ROW ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_row($this->result);
    		return $row;
    	}
     
     
     
    	/* Return query result row as an associative array */
    	function fetch_assoc( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_ASSOC ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_assoc($this->result);
    		return $row;
    	}
     
     
     
    	/* Return query result row as an associative array and an indexed array */
    	function fetch_both( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_BOTH ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_array($this->result, MYSQL_BOTH);
    		return $row;
    	}
     
     
     
    	/* Return query result as an array of arrays */
    	function fetch_array( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_ARRAY ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$arr = array( );
    		while ($row = @mysql_fetch_array($this->result))
    		{
    			$arr[] = $row;
    		}
     
    		return $arr;
    	}
     
     
     
    	/* Return query result as an array of single values */
    	function fetch_value_array( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_VALUE_ARRAY ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$arr = array( );
    		while ($row = @mysql_fetch_row($this->result))
    		{
    			$arr[] = $row[0];
    		}
     
    		return $arr;
    	}
     
     
     
    	/* Return single query result value */
    	function fetch_value( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_VALUE ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_row($this->result);
    		return $row[0];
    	}
     
     
     
    	/* Return the total number of queries executed during
    		 the lifetime of this object                         */
    	function num_queries( )
    	{
    		return $this->querycount;
    	}
     
     
     
    	/* get the id for the previous INSERT command */
    	function fetch_insert_id( )
    	{
    		return @mysql_insert_id($this->linkid);
    	}
     
     
     
    	/* get the errors, if any */
    	function fetch_error( )
    	{
    		return $this->error;
    	}
     
     
     
    	/* report the errors to the admin */
    	function error_report( )
    	{
    		// generate an error report and then act according to configuration
    		$error_report  = "An error has been generated by the server.\nFollowing is the debug information:\n\n";
    		$error_report .= "   *  File: {$this->file_name}\n";
    		$error_report .= "   *  Line: {$this->line}\n";
    		$error_report .= "   * Error: {$this->error}\n";
     
    		$error_report_short = "\n" . date('Y-m-d H:i:s') . " Error in {$this->file_name} on line {$this->line}: ERROR - {$this->error}";
     
    		// if a database query caused the error, show the query
    		if ('' != $this->query)
    		{
    			$error_report .= "   * Query: {$this->query}\n";
    			$error_report_short .= " [sql={$this->query}]";
    		}
     
    		// send the error as email if set
    		if (DB_ERR_EMAIL_ERRORS)
    		{
    			mail(DB_ERR_TO, trim(DB_ERR_SUBJECT), $error_report."\n\n".safe_var_export(debug_backtrace( ))."\n\n\$GLOBALS = ".safe_var_export($GLOBALS), 'From: '.DB_ERR_FROM."\r\n");
    		}
     
    		// log the error (remove line breaks and multiple concurrent spaces)
    		$this->logger(trim(preg_replace('/\\s+/', ' ', $error_report_short))."\n");
    	}
     
     
     
    	/* log any errors */
    	function logger($report)
    	{
    		if (DB_ERR_LOG_ERRORS)
    		{
    			$log = $this->log_path . "mysql.err";
    			$fp = fopen($log,'a+');
    			fwrite($fp,$report);
    			@chmod($log, 0777);
    			fclose($fp);
    		}
    	}
     
     
     
    	/* extract the arguments */
    	function load_arguments($args)
    	{
    		foreach ($args as $arg)
    		{
    			if ($this->super_debug)
    			{
    				echo '<hr />arg = (';
    				echo stripslashes(var_export($arg, true)).') - ';
    				echo 'is_line('.var_export(is_int($arg), true).') ';
    				echo 'is_file('.var_export(('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg)), true).') ';
    				echo 'is_database('.var_export(is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' ')), true).') ';
    				echo 'is_query('.var_export(0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg), true).') --- ';
    			}
     
    			if (is_int($arg)) // it's an integer
    			{
    				if ($this->super_debug) echo 'LINE - ';
    				$this->line = $arg;
    				if ($this->super_debug) echo $this->line;
    			}
    			elseif (('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg))) // the string begins with '/' or a drive letter
    			{
    				if ($this->super_debug) echo 'FILE - ';
    				$this->file_name = substr($arg, strpos($arg, FILE_PATH_END));
    				if ($this->super_debug) echo $this->file_name;
    			}
    			elseif (is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' '))) // there are no spaces
    			{
    				if ($this->super_debug) echo 'DATABASE - ';
    				$this->db = $arg;
    				if ($this->super_debug) echo $this->db;
    			}
    			elseif (0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg)) // it begins with a query word
    			{
    				if ($this->super_debug) echo 'QUERY - ';
    				$this->pass_query = $arg;
    				if ($this->super_debug) echo $this->pass_query;
    			}
    			else
    			{
    				if ($this->super_debug) echo 'UNKNOWN - ';
    				$arg_dump = var_export($arg, true);
    				$this->error = 'Unknown argument found: ' . $arg_dump;
    				if ($this->super_debug) echo $this->error;
    			}
    		}
     
    		// wait until after all arguments are entered before outputting error
    		// because the error may happen on the first argument and the other
    		// arguments have important error report data (it's what they're for)
    		if ('Unknown argument' == substr((string) $this->error, 0, 16))
    		{
    			$this->error_report( );
    		}
     
    		if ($this->super_debug) {echo'<pre>';print_r($this->get_arguments( ));echo'</pre>';}
    	}
     
     
     
    	/* clear the arguments */
    	function clear_arguments( )
    	{
    		// don't clear query or db as we may use them later
    		$this->line = false;
    		$this->file_name = false;
    		$this->error = false;
    		$this->pass_query = false;
    	}
     
     
     
    	/* return the arguments */
    	function get_arguments( )
    	{
    		$args['line'] = $this->line;
    		$args['file'] = $this->file_name;
    		$args['error'] = $this->error;
    		$args['query'] = $this->pass_query;
     
    		return $args;
    	}
     
    } // end of mysql class
     
     
     
    /*
     +---------------------------------------------------------------------------
     |   > Extra SQL Functions
     +---------------------------------------------------------------------------
    */
     
     
    /* escape the data before it gets queried into the database */
    function sani($data)
    {
    	if (is_array($data))
    	{
    		return array_map('sani', $data);
    	}
    	else
    	{
    		if (get_magic_quotes_gpc( ))
    		{
    			$data = stripslashes($data);
    		}
     
    #    $data = htmlentities($data, ENT_NOQUOTES); // convert html to &html;
     
    		if (function_exists('mysql_real_escape_string'))
    		{
    			$data = mysql_real_escape_string($data); // php 4.3.0+
    		}
    		else
    		{
    			$data = mysql_escape_string($data); // php 4.0+
    		}
     
    		return $data;
    	}
    }
     
     
    if ( ! function_exists('microtime_float'))
    {
    	function microtime_float( )
    	{
    		list($usec, $sec) = explode(' ', microtime( ));
    		return ((float)$usec + (float)$sec);
    	}
    }
     
     
    function safe_var_export($var)
    {
    	if ( ! is_array($var))
    	{
    		return var_export($var, true);
    	}
     
    	foreach ($var as $key => $data)
    	{
    		if (('GLOBALS' == $key) || ($data == $var))
    		{
    			$var[$key] = 'RECURSION';
    			continue;
    		}
    	}
     
    	return var_export($var, true);
    }
    Pour le fichier config.inc.php , j'ai copier tes codes également en y ajoutant mes coordonnées de nom de serveur, base de données, pseudo et mot de passe.
    Le tout à la place de ces anciens codes:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $mysql = new mysql($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
    $mysql->connect_select(__LINE__,__FILE__);
    Merci encore.
    L' ignorance, toujours mène à la servitude.

  10. #10
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Hum... tu ne peux pas utiliser les deux :
    soit tu pars sur PDO et tu bazardes la classe mysql, en remplaçant tous les endroits où elle est utilisée par une fonction PDO.
    soit tu conserves la classe mysql avec remplaçant les fonctions mysql_xxxx à l'intérieur par leurs équivalents mysqli, et tu ne touches pas au reste du code.
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  11. #11
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    Partir en mysqli serait mieux effectivement.
    Alors il est vrai que je me suis embrouillé en utilisant PDO pour la connexion.
    Pour ensuite utiliser mysqli.

    J'ai donc remodifier le fichier config.inc.php en y remplaçant la connexion PDO par mysqli comme indiqué ci dessous ligne 101:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    <?php
     
    /* Database settings */
    /* ----------------- */
    	$CFG_HOSTNAME = 'xxxxxx';
    	$CFG_USERNAME = 'xxxxxx';
    	$CFG_PASSWORD = 'xxxxx';
    	$CFG_DATABASE = 'xxxxxx';
     
    /* Table settings */
    /* -------------- */
    	$prefix = 'wc2_'; // table name prefix
     
    	define('T_CHAT'      , $prefix . 'chat'); // the in-game chat/personal notes table
    	define('T_GAME'      , $prefix . 'game'); // the game data table
    	define('T_HISTORY'   , $prefix . 'history'); // the moves history table
    	define('T_MESSAGE'   , $prefix . 'message'); // the game message table
    	define('T_PLAYER'    , $prefix . 'player'); // the player data table
    	define('T_STAT'      , $prefix . 'stat'); // the stats table
    	define('T_TALK'      , $prefix . 'talk'); // the player messaging table
    	define('T_TALK_GLUE' , $prefix . 'talk_glue'); // the message glue table
     
     
    /* Root Admin setting */
    /* ------------------ */
    	$CFG_ROOT_ADMIN = 'admin'; // Permanent admin username (case-sensitive)
     
     
    /* Server / Site settings */
    /* ---------------------- */
     
    	/*
    		  --- PLEASE READ ---
    
    		this first setting is the color theme for your webchess installation
    		look inside the /css directory and you will find several css files with a
    		filename like c_{color_name}.css.  pick one, and enter that name here, or you can easily
    		create your own, using one of the included styles as a guide.
    		if you do create your own, please add a pull request to my repo at
    		https://github.com/benjamw/chess/ so that others may have access to it.
    	*/
     
    	$CFG_COLOR_CSS      = 'c_green_black.css'; // the name of the color css file you wish to use (in the /css directory)
     
    	$CFG_MAINPAGE       = 'http://jeuxechecs.fr/jeux/'; // The home page of the webchess script (include closing / )
     
    	$CFG_SITENAME       = 'Echecs'; // The name of your website
     
    	$CFG_SESSIONTIMEOUT = 10; // Number of minutes before session timeout (0 to disable)
     
    	$CFG_EXPIREGAME     = 100; // Number of days before untouched games are deleted (0 to disable)
     
    	$CFG_EXPIREUSERS    = 100; // Number of days before untouched accounts are deleted (0 to disable)
     
    	$CFG_MINAUTORELOAD  = 15; // Minimum number of secs between automatic page reloads (0 to disable)
     
    	$CFG_USEEMAIL       = true; // SMTP operations.  Test it before putting it into production
     
    	$CFG_MAILADDRESS    = 'psftxa@free.fr'; // Email address people see when receiving WebChess generated mail
     
    	$CFG_MAXUSERS       = 0; // Maximum number of users allowed (0 to disable)
     
    	$CFG_CHANGEUSERNAME = false; // Whether a user can change their username from the main menu
     
    	$CFG_NEWUSERS       = true; // Whether a new user can register
     
    	$CFG_LONGDATE       = 'F j, Y \&\n\b\s\p\;g:i a'; // PHP date format
     
    	$CFG_SHORTDATE      = 'Y.m.d H:i'; // PHP date format
     
    	$CFG_CHESS960       = true; // Whether users can play Chess960 (Fischer Random Chess) games
     
    	$CFG_RATING_START   = 1500; // the starting ELO rating for new players
     
    	$CFG_RATING_STEP    = 32; // the max ELO rating change allowed per game
     
    	//$CFG_NAVLINKS       = '<a href="/">Home</a>'; // your site's nav links
    	$CFG_NAVLINKS       = '<a href="http://jeuxechecs.fr/index.html">Home</a>'; // your site's nav links
     
     
    /* MySQL Error / debug settings */
    /* ---------------------------- */
    	define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
    	define ('DB_ERR_LOG_ERRORS'  , true); // (true / false) set to true to log errors in mysql.err file
    	define ('DB_ERR_TO'          , 'your.name@yoursite.com'); // set your TO email address
    	define ('DB_ERR_SUBJECT'     , 'WebChess Query Error'); // don't really need to change this
    	define ('DB_ERR_FROM'        , $CFG_MAILADDRESS); // set your FROM email address (can be the same as TO above)
    	define ('DB_STATS_LOG'       , true); // (true / false) set to true to log query stats in mysql.err file (or database)
    	define ('FILE_PATH_END'      , 'webchess'); // set the name of the directory containing the script (with wrapping / )
     
     
     
    /* DEVELOPER USE ONLY */
    /* ------------------ */
     
    /* INCLUDE SOME GLOBAL INCLUDES */
    require_once 'mysql.class.php';
    require_once 'chessgame.inc.php';
     
    // instantiate the class and connect to the database
    $mysql = new mysqli($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
    $mysql->connect_select(__LINE__,__FILE__);
     
    /*try 
    {
      $cnx= new PDO("mysql:host=XXXXXXX;dbname=XXXXXXX", XXXXXX, XXXXXX, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));  
    } 
    catch ( Exception $e ) 
    {
      echo "Connection à MySQL impossible : ", $e->getMessage();
      die();
    }*/
     
     
    // instantiate the chess class
    $chess = new ChessGame( );
     
    define('DEBUG', false); // set to true for output of debugging code
     
    if (defined('DEBUG') && DEBUG)
    {
    	ini_set('display_errors', 'On');
    	error_reporting(E_ALL);
    	$mysql->error_debug = true; // Allows for error debug output
    	$mysql->query_debug = true; // Allows for output of all queries all the time
    	$mysql->super_debug = false; // Allows output of ALL debugging output
    	define('JS_DEBUG', 0); // set to 1 for really annoying jvascript debug
    }
    else // do not edit the following
    {
    	ini_set('display_errors', 'Off');
    	error_reporting(0); // set to 0 when releasing to public
    	$mysql->error_debug = false; // Allows for error debug output
    	$mysql->query_debug = false; // Allows for output of all queries all the time
    	$mysql->super_debug = false; // Allows output of ALL debugging output
    	define('JS_DEBUG', 0);
    }
     
    require_once('func.global.php');
    require_once('func.array.php');
    require_once('func.bitwise.php');
    require_once('message.class.php');
    require_once('phpass.class.php');
     
    $CFG_SESSIONTIMEOUT *= 60; // convert minutes to seconds
     
    date_default_timezone_set('UTC');
    Je n'ai donc rien modifié au fichier msql.class.php dont les codes sont en mysqli.
    Cependant voici le message d'erreur qu'il m'est retourné:
    Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'jeuXXXXXXfr'@'10.XXX.XX.84' (using password: YES) in /customers/6/0/9/jeuxechecs.fr/httpd.www/jeux/includes/config.inc.php on line 101 Fatal error: Call to undefined method mysqli::connect_select() in /customers/6/0/9/jeuxechecs.fr/httpd.www/jeux/includes/config.inc.php on line 102

    N'ayant jamais utilisé mysqly ainsi que mysql, je ne suis pas sur de mon code en ligne 101.
    Car jusqu' à présent j'ai toujours préféré PDO pour sa portabilité et sa sécurité.Et donc mis en oeuvre.
    L' ignorance, toujours mène à la servitude.

  12. #12
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Non, non, il faut que tu continues à appeler la classe mysql, que tu définis dans ton fichier mysql.class.php.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $mysql = new <span class="highlight">mysql</span>($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
    $mysql->connect_select(__LINE__,__FILE__);
    Et c'est cette classe qui utilise mysqli (comme dans ton message envoyé à 16h)

    (et moi aussi, je préfère PDO , mais là, ça sera sans doute moins pire de passer par mysqli. Ou alors tu réécris tout )
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  13. #13
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    J'ai donc modifier en ligne 101 et 102 comme ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    <?php
     
    /* Database settings */
    /* ----------------- */
    	$CFG_HOSTNAME = 'xx';
    	$CFG_USERNAME = 'xx';
    	$CFG_PASSWORD = 'xx';
    	$CFG_DATABASE = 'xx';
     
    /* Table settings */
    /* -------------- */
    	$prefix = 'wc2_'; // table name prefix
     
    	define('T_CHAT'      , $prefix . 'chat'); // the in-game chat/personal notes table
    	define('T_GAME'      , $prefix . 'game'); // the game data table
    	define('T_HISTORY'   , $prefix . 'history'); // the moves history table
    	define('T_MESSAGE'   , $prefix . 'message'); // the game message table
    	define('T_PLAYER'    , $prefix . 'player'); // the player data table
    	define('T_STAT'      , $prefix . 'stat'); // the stats table
    	define('T_TALK'      , $prefix . 'talk'); // the player messaging table
    	define('T_TALK_GLUE' , $prefix . 'talk_glue'); // the message glue table
     
     
    /* Root Admin setting */
    /* ------------------ */
    	$CFG_ROOT_ADMIN = 'admin'; // Permanent admin username (case-sensitive)
     
     
    /* Server / Site settings */
    /* ---------------------- */
     
    	/*
    		  --- PLEASE READ ---
    
    		this first setting is the color theme for your webchess installation
    		look inside the /css directory and you will find several css files with a
    		filename like c_{color_name}.css.  pick one, and enter that name here, or you can easily
    		create your own, using one of the included styles as a guide.
    		if you do create your own, please add a pull request to my repo at
    		https://github.com/benjamw/chess/ so that others may have access to it.
    	*/
     
    	$CFG_COLOR_CSS      = 'c_green_black.css'; // the name of the color css file you wish to use (in the /css directory)
     
    	$CFG_MAINPAGE       = 'http://jeuxechecs.fr/jeux/'; // The home page of the webchess script (include closing / )
     
    	$CFG_SITENAME       = 'Echecs'; // The name of your website
     
    	$CFG_SESSIONTIMEOUT = 10; // Number of minutes before session timeout (0 to disable)
     
    	$CFG_EXPIREGAME     = 100; // Number of days before untouched games are deleted (0 to disable)
     
    	$CFG_EXPIREUSERS    = 100; // Number of days before untouched accounts are deleted (0 to disable)
     
    	$CFG_MINAUTORELOAD  = 15; // Minimum number of secs between automatic page reloads (0 to disable)
     
    	$CFG_USEEMAIL       = true; // SMTP operations.  Test it before putting it into production
     
    	$CFG_MAILADDRESS    = 'psftxa@free.fr'; // Email address people see when receiving WebChess generated mail
     
    	$CFG_MAXUSERS       = 0; // Maximum number of users allowed (0 to disable)
     
    	$CFG_CHANGEUSERNAME = false; // Whether a user can change their username from the main menu
     
    	$CFG_NEWUSERS       = true; // Whether a new user can register
     
    	$CFG_LONGDATE       = 'F j, Y \&\n\b\s\p\;g:i a'; // PHP date format
     
    	$CFG_SHORTDATE      = 'Y.m.d H:i'; // PHP date format
     
    	$CFG_CHESS960       = true; // Whether users can play Chess960 (Fischer Random Chess) games
     
    	$CFG_RATING_START   = 1500; // the starting ELO rating for new players
     
    	$CFG_RATING_STEP    = 32; // the max ELO rating change allowed per game
     
    	//$CFG_NAVLINKS       = '<a href="/">Home</a>'; // your site's nav links
    	$CFG_NAVLINKS       = '<a href="http://jeuxechecs.fr/index.html">Home</a>'; // your site's nav links
     
     
    /* MySQL Error / debug settings */
    /* ---------------------------- */
    	define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
    	define ('DB_ERR_LOG_ERRORS'  , true); // (true / false) set to true to log errors in mysql.err file
    	define ('DB_ERR_TO'          , 'your.name@yoursite.com'); // set your TO email address
    	define ('DB_ERR_SUBJECT'     , 'WebChess Query Error'); // don't really need to change this
    	define ('DB_ERR_FROM'        , $CFG_MAILADDRESS); // set your FROM email address (can be the same as TO above)
    	define ('DB_STATS_LOG'       , true); // (true / false) set to true to log query stats in mysql.err file (or database)
    	define ('FILE_PATH_END'      , 'webchess'); // set the name of the directory containing the script (with wrapping / )
     
     
     
    /* DEVELOPER USE ONLY */
    /* ------------------ */
     
    /* INCLUDE SOME GLOBAL INCLUDES */
    require_once 'mysql.class.php';
    require_once 'chessgame.inc.php';
     
    // instantiate the class and connect to the database
    $mysql = new <span class="highlight">mysql</span>($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
    $mysql->connect_select(__LINE__,__FILE__);
     
    /*try 
    {
      $cnx= new PDO("mysql:host=jeuxechecs.fr.mysql;dbname=jeuxechecs_fr", jeuxechecs.fr, VnXte5dM, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));  
    } 
    catch ( Exception $e ) 
    {
      echo "Connection à MySQL impossible : ", $e->getMessage();
      die();
    }*/
     
     
    // instantiate the chess class
    $chess = new ChessGame( );
     
    define('DEBUG', false); // set to true for output of debugging code
     
    if (defined('DEBUG') && DEBUG)
    {
    	ini_set('display_errors', 'On');
    	error_reporting(E_ALL);
    	$mysql->error_debug = true; // Allows for error debug output
    	$mysql->query_debug = true; // Allows for output of all queries all the time
    	$mysql->super_debug = false; // Allows output of ALL debugging output
    	define('JS_DEBUG', 0); // set to 1 for really annoying jvascript debug
    }
    else // do not edit the following
    {
    	ini_set('display_errors', 'Off');
    	error_reporting(0); // set to 0 when releasing to public
    	$mysql->error_debug = false; // Allows for error debug output
    	$mysql->query_debug = false; // Allows for output of all queries all the time
    	$mysql->super_debug = false; // Allows output of ALL debugging output
    	define('JS_DEBUG', 0);
    }
     
    require_once('func.global.php');
    require_once('func.array.php');
    require_once('func.bitwise.php');
    require_once('message.class.php');
    require_once('phpass.class.php');
     
    $CFG_SESSIONTIMEOUT *= 60; // convert minutes to seconds
     
    date_default_timezone_set('UTC');
    Cependant voici le message qu'il m'est retourné:
    Parse error: syntax error, unexpected '<' in /customers/6/0/9/jeuxechecs.fr/httpd.www/jeux/includes/config.inc.php on line 101

    Comme indiqué il y a une erreur de syntaxe.Mais comme je ne connais pas ces codes, je préfères te montrer ceux ci.Je suis sûr que tu trouveras.
    L' ignorance, toujours mène à la servitude.

  14. #14
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Oui bon, même si tu ne maitrises pas le code, il devrait quand même y avoir un truc qui te choque:
    Ligne 101 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $mysql = new <span class="highlight">mysql</span>($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
    Tu as aussi copié la mise en forme du forum quand tu as copié le code
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  15. #15
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    "Tu as aussi copié la mise en forme du forum quand tu as copié le code ?"

    Non j'ai copié les deux lignes de codes uniquement.
    Bien sur que les balises <span> me choquent!
    Avec ce html mélangé au php ça ne peut certainement pas fonctionner.
    Mais j'ai essayer quand même d'appliquer cela!Car je n'étais plus à ça près.

    Maintenant je m'y prends autrement.
    Voici des codes qui fonctionnent en local:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <?php
    	$CFG_HOSTNAME = 'localhost';
    	$CFG_USERNAME = 'root';
    	$CFG_PASSWORD = '';
    	$CFG_DATABASE = 'Test';
     
    	$mysql = new mysqli($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
    if ($mysql->connect_error) {
        die('Erreur de connexion (' . $mysql->connect_errno . ') '
                . $mysql->connect_error);
    }
    echo 'Succès... ' . $mysql->host_info . "\n";
    echo " bon";
    exit();
    ?>
    Dont voici le résultat:
    Succès... localhost via TCP/IP bon

    Les même codes (sauf pour les indications du serveur distant bien sûr):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <?php
    	$CFG_HOSTNAME = 'XX';
    	$CFG_USERNAME = 'XX';
    	$CFG_PASSWORD = 'XX';
    	$CFG_DATABASE = 'XX';
     
    	$mysql = new mysqli($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
    if ($mysql->connect_error) {
        die('Erreur de connexion (' . $mysql->connect_errno . ') '
                . $mysql->connect_error);
    }
    echo 'Succès... ' . $mysql->host_info . "\n";
    echo " bon";
    exit();
    ?>
    ET voici le message d'erreur:
    Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'jeuxxxxfr'@'xx.xx.xx.xx' (using password: YES) in /customers/6/0/9/jeuxechecs.fr/httpd.www/jeux/includes/testconnect.php on line 11 Erreur de connexion (1045) Access denied for user 'jeuxechecs.fr'@'10.246.64.84' (using password: YES)

    Conclusion:
    Pour ces codes aussi cela fonctionne en local.Mais pas sur serveur distant.
    Malgré que j'utilise cette fois ci mysqli!
    J'aurai bien envie de poser le problème à l'un des techniciens qui gère le serveur distant auquel mon site est installé.
    Qu'en penses tu?
    L' ignorance, toujours mène à la servitude.

  16. #16
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    Bon j'ai arrêter de fumer la moquette et redeviens sérieux.lol.

    Alors après m'être renseigné auprès de mon hébergeur de site, j'ai donc appris qu'il est possible d'utiliser l'API mysqli.
    Et en fait même avec l' API mysql j'arrive aussi à me connecter comme je le démontre ci dessous:

    Ensuite d'autres recherches m'ont permis de me connecter à ma base de données comme le démontre le résultat retourné par le message:
    connection ok
    Voici les codes auxquels j' interromps le programme ligne 108 par une sortie de celui ci afin d'obtenir le message m'indiquant la bonne connexion à la BdD:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    <?php
    /* Table settings */
    /* -------------- */
    	$prefix = 'wc2_'; // table name prefix
     
    	define('T_CHAT'      , $prefix . 'chat'); // the in-game chat/personal notes table
    	define('T_GAME'      , $prefix . 'game'); // the game data table
    	define('T_HISTORY'   , $prefix . 'history'); // the moves history table
    	define('T_MESSAGE'   , $prefix . 'message'); // the game message table
    	define('T_PLAYER'    , $prefix . 'player'); // the player data table
    	define('T_STAT'      , $prefix . 'stat'); // the stats table
    	define('T_TALK'      , $prefix . 'talk'); // the player messaging table
    	define('T_TALK_GLUE' , $prefix . 'talk_glue'); // the message glue table
     
     
    /* Root Admin setting */
    /* ------------------ */
    	$CFG_ROOT_ADMIN = 'admin'; // Permanent admin username (case-sensitive)
     
     
    /* Server / Site settings */
    /* ---------------------- */
     
    	/*
    		  --- PLEASE READ ---
    
    		this first setting is the color theme for your webchess installation
    		look inside the /css directory and you will find several css files with a
    		filename like c_{color_name}.css.  pick one, and enter that name here, or you can easily
    		create your own, using one of the included styles as a guide.
    		if you do create your own, please add a pull request to my repo at
    		https://github.com/benjamw/chess/ so that others may have access to it.
    	*/
     
    	$CFG_COLOR_CSS      = 'c_green_black.css'; // the name of the color css file you wish to use (in the /css directory)
     
    	$CFG_MAINPAGE       = 'http://xxxxxxxxxx/'; // The home page of the webchess script (include closing / )
     
    	$CFG_SITENAME       = 'Echecs'; // The name of your website
     
    	$CFG_SESSIONTIMEOUT = 10; // Number of minutes before session timeout (0 to disable)
     
    	$CFG_EXPIREGAME     = 100; // Number of days before untouched games are deleted (0 to disable)
     
    	$CFG_EXPIREUSERS    = 100; // Number of days before untouched accounts are deleted (0 to disable)
     
    	$CFG_MINAUTORELOAD  = 15; // Minimum number of secs between automatic page reloads (0 to disable)
     
    	$CFG_USEEMAIL       = true; // SMTP operations.  Test it before putting it into production
     
    	$CFG_MAILADDRESS    = 'xxxxx@xxxxx'; // Email address people see when receiving WebChess generated mail
     
    	$CFG_MAXUSERS       = 0; // Maximum number of users allowed (0 to disable)
     
    	$CFG_CHANGEUSERNAME = false; // Whether a user can change their username from the main menu
     
    	$CFG_NEWUSERS       = true; // Whether a new user can register
     
    	$CFG_LONGDATE       = 'F j, Y \&\n\b\s\p\;g:i a'; // PHP date format
     
    	$CFG_SHORTDATE      = 'Y.m.d H:i'; // PHP date format
     
    	$CFG_CHESS960       = true; // Whether users can play Chess960 (Fischer Random Chess) games
     
    	$CFG_RATING_START   = 1500; // the starting ELO rating for new players
     
    	$CFG_RATING_STEP    = 32; // the max ELO rating change allowed per game
     
    	//$CFG_NAVLINKS       = '<a href="/">Home</a>'; // your site's nav links
    	$CFG_NAVLINKS       = '<a href="http://xxxxxxxxxx.html">Home</a>'; // your site's nav links
     
     
    /* MySQL Error / debug settings */
    /* ---------------------------- */
    	define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
    	define ('DB_ERR_LOG_ERRORS'  , true); // (true / false) set to true to log errors in mysql.err file
    	define ('DB_ERR_TO'          , 'your.name@yoursite.com'); // set your TO email address
    	define ('DB_ERR_SUBJECT'     , 'WebChess Query Error'); // don't really need to change this
    	define ('DB_ERR_FROM'        , $CFG_MAILADDRESS); // set your FROM email address (can be the same as TO above)
    	define ('DB_STATS_LOG'       , true); // (true / false) set to true to log query stats in mysql.err file (or database)
    	define ('FILE_PATH_END'      , 'webchess'); // set the name of the directory containing the script (with wrapping / )
     
     
     
    /* DEVELOPER USE ONLY */
    /* ------------------ */
     
    /* INCLUDE SOME GLOBAL INCLUDES */
    require_once 'mysql.class.php';
    require_once 'chessgame.inc.php';
     
    // instantiate the class and connect to the database
    //$mysql = new mysqli($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
     
    $mysql = @mysql_connect('nom_d_hôte_ la_base','nom_utilisateur','mot_passe');
    if (!$mysql) 
    {
     	echo "<p>Connexion à la base de données impossible. Veuillez vérifier les paramètres dans le fichier connexion.</p>";
    	exit();
    }
     
    if ( !mysql_select_db('nom_de_la_base',$mysql) ) 
    { 
    	echo "<p>Sélection de la base de données impossible. Veuillez vérifier les paramètres dans le fichier connexion.</p>";
    	exit(); 
    }
    echo "connection ok";
    exit();
    $mysql->connect_select(__LINE__,__FILE__);
     
    // instantiate the chess class
    $chess = new ChessGame( );
     
    define('DEBUG', false); // set to true for output of debugging code
     
    if (defined('DEBUG') && DEBUG)
    {
    	ini_set('display_errors', 'On');
    	error_reporting(E_ALL);
    	$mysql->error_debug = true; // Allows for error debug output
    	$mysql->query_debug = true; // Allows for output of all queries all the time
    	$mysql->super_debug = false; // Allows output of ALL debugging output
    	define('JS_DEBUG', 0); // set to 1 for really annoying jvascript debug
    }
    else // do not edit the following
    {
    	ini_set('display_errors', 'Off');
    	error_reporting(0); // set to 0 when releasing to public
    	$mysql->error_debug = false; // Allows for error debug output
    	$mysql->query_debug = false; // Allows for output of all queries all the time
    	$mysql->super_debug = false; // Allows output of ALL debugging output
    	define('JS_DEBUG', 0);
    }
     
    require_once('func.global.php');
    require_once('func.array.php');
    require_once('func.bitwise.php');
    require_once('message.class.php');
    require_once('phpass.class.php');
     
    $CFG_SESSIONTIMEOUT *= 60; // convert minutes to seconds
     
    date_default_timezone_set('UTC');
    Cependant voici un message d'erreur qu'il m'est retourné lorsque je laisse le programme se dérouler sans interruption par exit:
    Fatal error: Call to a member function connect_select() on resource in /customers/6/0/9/jeuxechecs.fr/httpd.www/jeux/includes/config.inc.php on line 109
    Cela signifie t-il qu'il existe un problème dans une ou plusieurs lignes de codes du fichier nommé mysql.class.php ? Ou est ce la ligne de codes
    Merci de bien vouloir continuer à m'aider là où je suis arrivé.
    L' ignorance, toujours mène à la servitude.

  17. #17
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Novembre 2013
    Messages
    99
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 99
    Points : 51
    Points
    51
    Par défaut
    Là j'arrête de boire!!!Lol.
    Et j'ai trouvé la précédente erreur.
    C'était simplement une faute de ma part à laquelle je ne m'attarderai pas.Car sans intérêt.
    Et maintenant voici le message d'erreur suivant (sans doute un peu plus sérieux):
    Fatal error: Cannot redeclare mysql::connect() in /customers/6/0/9/jeuxechecs.fr/httpd.www/jeux/includes/mysql.class.php on line 129
    Et les codes du fichiers mysql.class.php s'y rapportant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    <?php
    /*
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    /
    */
     
    class mysql
    {
    	var $linkid;      // MySQL Resource ID
    	var $host;        // MySQL Host name
    	var $user;        // MySQL Username
    	var $pswd;        // MySQL password
    	var $db;          // MySQL Database
    	var $query;       // MySQL query
    	var $query_time;  // Time it took to run the query
    	var $pass_query;  // Query passed by argument
    	var $result;      // Query result
    	var $line;        // Line of query
    	var $file;        // File of query
    	var $error;       // Any error message encountered while running
    	var $log_path;    // The path to the log file
    	var $querycount;  // Total number of queries executed since class inception
    	var $error_debug; // Allows for error debug output
    	var $query_debug; // Allows for output of all queries all the time
    	var $super_debug; // Allows output of ALL debugging output
     
     
     
    	/* Class constructor.  Initializes the host, user, pswd, db and log fields */
    	function mysql($host, $user, $pswd, $db, $log_path = './')
    	{
     
    		/*#
    		  #
    		  # The following was moved to the config file for
    		  # ease of use by the admin (so they don't have to config
    		  # multiple files, and only have to edit one),
    		  # but the original source was left here for those who wish
    		  # to implement this class in their own creations.
    		  #
    		  # to enable, just change  /*#  above to  //*#  and edit settings
    		  #
    		  # to disable, change  //*#  above to  /*#
    		  # and copy-paste this section into your own config file
    		  #
    
    		// BEGIN CONFIG ----------------------
    
    		define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
    		define ('DB_ERR_LOG_ERRORS'  , true); // (true / false) set to true to log errors in mysql.err file
    		define ('DB_ERR_TO'          , 'yourname@yoursite.com'); // set your TO email address
    		define ('DB_ERR_SUBJECT'     , 'Query Error'); // don't really need to change this
    		define ('DB_ERR_FROM'        , 'yourname@yoursite.com'); // set your FROM email address (can be the same as TO above)
    		define ('FILE_PATH_END'      , '/yourscript/'); // the name of the directory containing the script (with wrapping / )
    
    		// END CONFIG ------------------------
    
    		  #
    		  # end of config section removal
    		  #
    		  #*/
     
    		$this->host = $host;
    		$this->user = $user;
    		$this->pswd = $pswd;
    		$this->db   = $db;
    		$this->log_path = $log_path;
     
    		// each of these can be set independently as needed
    		$this->error_debug = false; // set to true for output of errors
    		$this->query_debug = false; // set to true for output of every query
    		$this->super_debug = false; // set to true for other debugging output (like passed query arguments, etc.)
     
    		// make sure the log path ends with /
    		if (strrpos($this->log_path,'/') != (strlen($this->log_path) - 1))
    		{
    			$this->log_path .= '/';
    		}
    	}
     
     
     
    	/* Connect to the MySQL database server */
    	function connect( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->load_arguments($args);
    		}
     
    		$this->linkid = @mysql_connect($this->host, $this->user, $this->pswd);
     
    		if ( ! $this->linkid)
    		{
    			$this->error = mysql_errno( ).': '.mysql_error( );
    			$this->error_report( );
     
    			if ($this->error_debug)
    			{
    				echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
    			}
    			else
    			{
    				die('There was a database error. An email has been sent to the system administrator.');
    			}
    		}
    	}
    	/* Selects the MySQL Database */
    	function select( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->load_arguments($args);
    		}
     
    		if ( ! @mysql_select_db($this->db, $this->linkid))
    		{
    			$this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
    			$this->error_report( );
     
    			if ($this->error_debug)
    			{
    				echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
    			}
    			else
    			{
    				die('There was a database error. An email has been sent to the system administrator.');
    			}
    		}
    	}
     
    	/* Connects to the server AND selects the default database in one function */
    	function connect_select( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		$this->clear_arguments( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->load_arguments($args);
    		}
     
    		$this->connect( );
    		$this->select( );
    	}
     
     
     
    	/* Execute Database Query */
    	function query( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( ); // don't clear unless we have new
    			$this->load_arguments($args);
     
    			if (false !== $this->pass_query)
    			{
    				$this->query = $this->pass_query;
    			}
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'QUERY ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		$done = true; // innocent until proven guilty
     
    		// start time logging
    		$time = microtime_float( );
    		$this->result = @mysql_query($this->query, $this->linkid);
    		$this->query_time = microtime_float( ) - $time;
     
    		if ($this->query_debug)
    		{
    			$this->query = trim(preg_replace('/\\s+/', ' ', $this->query));
    			echo "<div style='background:white;color:black;'><br />{$this->query} - <strong>Aff(".$this->affected_rows( ).") - {$this->file_name}: {$this->line}</strong></div>";
    		}
     
    		if ( ! $this->result)
    		{
    			$this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
    			$this->error_report( );
     
    			if ($this->error_debug)
    			{
    				echo "<div style='background:#900;color:white;'>There was an error in your query in {$this->file_name} on line {$this->line}: ERROR - {$this->error}<br />Query: {$this->query}</div>";
    				print_r(debug_backtrace( ));
    			}
    			else
    			{
    				$this->error = 'There was a database error. An email has been sent to the system administrator.';
    			}
     
    			$done = false;
    		}
     
    		if ($done)
    		{
    			$this->querycount++;
    			return $this->result;
    		}
     
    		return false;
    	}
     
     
     
    	/* Determine total rows affected by query */
    	function affected_rows( )
    	{
    		$count = @mysql_affected_rows($this->linkid);
    		return $count;
    	}
     
     
     
    	/* Determine total rows returned by query */
    	function num_rows( )
    	{
    		$count = @mysql_num_rows($this->result);
     
    		if ( ! $count)
    		{
    			return 0;
    		}
     
    		return $count;
    	}
     
     
    	/** public function insert
    	 *		Insert the associative data array into the table.
    	 *			$data['field_name'] = value
    	 *			$data['field_name2'] = value2
    	 *		If the field name has a trailing space: $data['field_name ']
    	 *		then the query will insert the data with no sanitation
    	 *		or wrapping quotes (good for function calls, like NOW( )).
    	 *
    	 * @param string table name
    	 * @param array associative data array
    	 * @param string [optional] where clause (for updates)
    	 * @param bool [optional] whether or not we should replace values (true / false)
    	 * @action execute a mysql query
    	 * @return int insert id for row
    	 */
    	function insert($table, $data_array, $where = '', $replace = false)
    	{
    		$where = trim($where);
    		$replace = (bool) $replace;
     
    		if ('' == $where) {
    			$query  = (false == $replace) ? ' INSERT ' : ' REPLACE ';
    			$query .= ' INTO ';
    		}
    		else {
    			$query = ' UPDATE ';
    		}
     
    		$query .= '`'.$table.'`';
     
    		if ( ! is_array($data_array)) {
    			throw new MySQLException(__METHOD__.': Trying to insert non-array data');
    		}
    		else {
    			$query .= ' SET ';
    			foreach ($data_array as $field => $value) {
    				if (is_null($value)) {
    					$query .=  " `{$field}` = NULL , ";
    				}
    				elseif (' ' == substr($field, -1, 1)) { // i picked a trailing space because it's an illegal field name in MySQL
    					$field = trim($field);
    					$query .= " `{$field}` = {$value} , ";
    				}
    				else {
    					$query .= " `{$field}` = '".sani($value)."' , ";
    				}
    			}
     
    			$query = substr($query, 0, -2).' '; // remove the last comma (but preserve those spaces)
    		}
     
    		$query .= ' '.$where.' ';
    		$this->query = $query;
    		$return = $this->query( );
     
    		if ('' == $where) {
    			return $this->fetch_insert_id( );
    		}
    		else {
    			return $return;
    		}
    	}
     
     
    	/** public function multi_insert
    	 *		Insert the array of associative data arrays into the table.
    	 *			$data[0]['field_name'] = value
    	 *			$data[0]['field_name2'] = value2
    	 *			$data[0]['DBWHERE'] = where clause [optional]
    	 *			$data[1]['field_name'] = value
    	 *			$data[1]['field_name2'] = value2
    	 *			$data[1]['DBWHERE'] = where clause [optional]
    	 *
    	 * @param string table name
    	 * @param array associative data array
    	 * @param bool [optional] whether or not we should replace values (true / false)
    	 * @action execute multiple mysql queries
    	 * @return array insert ids for rows (with original keys preserved)
    	 */
    	function multi_insert($table, $data_array, $replace = false)
    	{
    		if ( ! is_array($data_array)) {
    			throw new MySQLException(__METHOD__.': Trying to multi-insert non-array data');
    		}
    		else {
    			$result = array( );
     
    			foreach ($data_array as $key => $row) {
    				$where = (isset($row['DBWHERE'])) ? $row['DBWHERE'] : '';
    				unset($row['DBWHERE']);
    				$result[$key] = $this->insert($table, $row, $where, $replace);
    			}
    		}
     
    		return $result;
    	}
     
     
    	/** public function delete
    	 *		Delete the row from the table
    	 *
    	 * @param string table name
    	 * @param string where clause
    	 * @action execute a mysql query
    	 * @return result
    	 */
    	function delete($table, $where)
    	{
    		$query = "
    			DELETE
    			FROM `{$table}`
    			{$where}
    		";
     
    		$this->query = $query;
     
    		try {
    			return $this->query( );
    		}
    		catch (MySQLException $e) {
    			throw $e;
    		}
    	}
     
     
    	/** public function multi_delete
    	 *		Delete the array of data from the table.
    	 *			$table[0] = table name
    	 *			$table[1] = table name
    	 *
    	 *			$where[0] = where clause
    	 *			$where[1] = where clause
    	 *
    	 *		If recursive is true, all combinations of table name
    	 *		and where clauses will be executed.
    	 *
    	 *		If only one table name is set, that table will
    	 *		be used for all of the queries, looping through
    	 *		the where array
    	 *
    	 *		If only one where clause is set, that where clause
    	 *		will be used for all of the queries, looping through
    	 *		the table array
    	 *
    	 * @param mixed table name array or single string
    	 * @param mixed where clause array or single string
    	 * @param bool optional recursive (default false)
    	 * @action execute multiple mysql queries
    	 * @return array results
    	 */
    	function multi_delete($table_array, $where_array, $recursive = false)
    	{
    		if ( ! is_array($table_array)) {
    			$recursive = false;
    			$table_array = (array) $table_array;
    		}
     
    		if ( ! is_array($where_array)) {
    			$recursive = false;
    			$where_array = (array) $where_array;
    		}
     
    		if ($recursive) {
    			foreach ($table_array as $table) {
    				foreach ($where_array as $where) {
    					$result[] = $this->delete($table, $where);
    				}
    			}
    		}
    		else {
    			if (count($table_array) == count($where_array)) {
    				for ($i = 0, $count = count($table_array); $i < $count; ++$i) {
    					$result[] = $this->delete($table_array[$i], $where_array[$i]);
    				}
    			}
    			elseif (1 == count($table_array)) {
    				$table = $table_array[0];
    				foreach ($where_array as $where) {
    					$result[] = $this->delete($table, $where);
    				}
    			}
    			elseif (1 == count($where_array)) {
    				$where = $where_array[0];
    				foreach ($table_array as $table) {
    					$result[] = $this->delete($table, $where);
    				}
    			}
    			else {
    				throw new MySQLException(__METHOD__.': Trying to multi-delete with incompatible array sizes');
    			}
    		}
     
    		return $result;
    	}
     
     
     
    	/* Return query result row as an object */
    	function fetch_object( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_OBJECT ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_object($this->result);
    		return $row;
    	}
     
     
     
    	/* Return query result row as an indexed array */
    	function fetch_row( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_ROW ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_row($this->result);
    		return $row;
    	}
     
     
     
    	/* Return query result row as an associative array */
    	function fetch_assoc( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_ASSOC ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_assoc($this->result);
    		return $row;
    	}
     
     
     
    	/* Return query result row as an associative array and an indexed array */
    	function fetch_both( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_BOTH ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_array($this->result, MYSQL_BOTH);
    		return $row;
    	}
     
     
     
    	/* Return query result as an array of arrays */
    	function fetch_array( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_ARRAY ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$arr = array( );
    		while ($row = @mysql_fetch_array($this->result))
    		{
    			$arr[] = $row;
    		}
     
    		return $arr;
    	}
     
     
     
    	/* Return query result as an array of single values */
    	function fetch_value_array( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_VALUE_ARRAY ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$arr = array( );
    		while ($row = @mysql_fetch_row($this->result))
    		{
    			$arr[] = $row[0];
    		}
     
    		return $arr;
    	}
     
     
     
    	/* Return single query result value */
    	function fetch_value( )
    	{
    		$num_args = func_num_args( );
    		$args     = func_get_args( );
     
    		// get the arguments, if any
    		if (0 != $num_args)
    		{
    			$this->clear_arguments( );
    			$this->load_arguments($args);
    		}
     
    		if ($this->super_debug)
    		{
    			echo 'FETCH_VALUE ';
    			echo '<pre>';
    			print_r($this->get_arguments( ));
    			echo '</pre>';
    		}
     
    		if (false !== $this->pass_query)
    		{
    			$this->query = $this->pass_query;
    			$this->query( );
    		}
     
    		$row = @mysql_fetch_row($this->result);
    		return $row[0];
    	}
     
     
     
    	/* Return the total number of queries executed during
    		 the lifetime of this object                         */
    	function num_queries( )
    	{
    		return $this->querycount;
    	}
     
     
     
    	/* get the id for the previous INSERT command */
    	function fetch_insert_id( )
    	{
    		return @mysql_insert_id($this->linkid);
    	}
     
     
     
    	/* get the errors, if any */
    	function fetch_error( )
    	{
    		return $this->error;
    	}
     
     
     
    	/* report the errors to the admin */
    	function error_report( )
    	{
    		// generate an error report and then act according to configuration
    		$error_report  = "An error has been generated by the server.\nFollowing is the debug information:\n\n";
    		$error_report .= "   *  File: {$this->file_name}\n";
    		$error_report .= "   *  Line: {$this->line}\n";
    		$error_report .= "   * Error: {$this->error}\n";
     
    		$error_report_short = "\n" . date('Y-m-d H:i:s') . " Error in {$this->file_name} on line {$this->line}: ERROR - {$this->error}";
     
    		// if a database query caused the error, show the query
    		if ('' != $this->query)
    		{
    			$error_report .= "   * Query: {$this->query}\n";
    			$error_report_short .= " [sql={$this->query}]";
    		}
     
    		// send the error as email if set
    		if (DB_ERR_EMAIL_ERRORS)
    		{
    			mail(DB_ERR_TO, trim(DB_ERR_SUBJECT), $error_report."\n\n".safe_var_export(debug_backtrace( ))."\n\n\$GLOBALS = ".safe_var_export($GLOBALS), 'From: '.DB_ERR_FROM."\r\n");
    		}
     
    		// log the error (remove line breaks and multiple concurrent spaces)
    		$this->logger(trim(preg_replace('/\\s+/', ' ', $error_report_short))."\n");
    	}
     
     
     
    	/* log any errors */
    	function logger($report)
    	{
    		if (DB_ERR_LOG_ERRORS)
    		{
    			$log = $this->log_path . "mysql.err";
    			$fp = fopen($log,'a+');
    			fwrite($fp,$report);
    			@chmod($log, 0777);
    			fclose($fp);
    		}
    	}
     
     
     
    	/* extract the arguments */
    	function load_arguments($args)
    	{
    		foreach ($args as $arg)
    		{
    			if ($this->super_debug)
    			{
    				echo '<hr />arg = (';
    				echo stripslashes(var_export($arg, true)).') - ';
    				echo 'is_line('.var_export(is_int($arg), true).') ';
    				echo 'is_file('.var_export(('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg)), true).') ';
    				echo 'is_database('.var_export(is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' ')), true).') ';
    				echo 'is_query('.var_export(0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg), true).') --- ';
    			}
     
    			if (is_int($arg)) // it's an integer
    			{
    				if ($this->super_debug) echo 'LINE - ';
    				$this->line = $arg;
    				if ($this->super_debug) echo $this->line;
    			}
    			elseif (('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg))) // the string begins with '/' or a drive letter
    			{
    				if ($this->super_debug) echo 'FILE - ';
    				$this->file_name = substr($arg, strpos($arg, FILE_PATH_END));
    				if ($this->super_debug) echo $this->file_name;
    			}
    			elseif (is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' '))) // there are no spaces
    			{
    				if ($this->super_debug) echo 'DATABASE - ';
    				$this->db = $arg;
    				if ($this->super_debug) echo $this->db;
    			}
    			elseif (0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg)) // it begins with a query word
    			{
    				if ($this->super_debug) echo 'QUERY - ';
    				$this->pass_query = $arg;
    				if ($this->super_debug) echo $this->pass_query;
    			}
    			else
    			{
    				if ($this->super_debug) echo 'UNKNOWN - ';
    				$arg_dump = var_export($arg, true);
    				$this->error = 'Unknown argument found: ' . $arg_dump;
    				if ($this->super_debug) echo $this->error;
    			}
    		}
     
    		// wait until after all arguments are entered before outputting error
    		// because the error may happen on the first argument and the other
    		// arguments have important error report data (it's what they're for)
    		if ('Unknown argument' == substr((string) $this->error, 0, 16))
    		{
    			$this->error_report( );
    		}
     
    		if ($this->super_debug) {echo'<pre>';print_r($this->get_arguments( ));echo'</pre>';}
    	}
     
     
     
    	/* clear the arguments */
    	function clear_arguments( )
    	{
    		// don't clear query or db as we may use them later
    		$this->line = false;
    		$this->file_name = false;
    		$this->error = false;
    		$this->pass_query = false;
    	}
     
     
     
    	/* return the arguments */
    	function get_arguments( )
    	{
    		$args['line'] = $this->line;
    		$args['file'] = $this->file_name;
    		$args['error'] = $this->error;
    		$args['query'] = $this->pass_query;
     
    		return $args;
    	}
     
    } // end of mysql class
     
     
     
    /*
     +---------------------------------------------------------------------------
     |   > Extra SQL Functions
     +---------------------------------------------------------------------------
    */
     
     
    /* escape the data before it gets queried into the database */
    function sani($data)
    {
    	if (is_array($data))
    	{
    		return array_map('sani', $data);
    	}
    	else
    	{
    		if (get_magic_quotes_gpc( ))
    		{
    			$data = stripslashes($data);
    		}
     
    #    $data = htmlentities($data, ENT_NOQUOTES); // convert html to &html;
     
    		if (function_exists('mysql_real_escape_string'))
    		{
    			$data = mysql_real_escape_string($data); // php 4.3.0+
    		}
    		else
    		{
    			$data = mysql_escape_string($data); // php 4.0+
    		}
     
    		return $data;
    	}
    }
     
     
    if ( ! function_exists('microtime_float'))
    {
    	function microtime_float( )
    	{
    		list($usec, $sec) = explode(' ', microtime( ));
    		return ((float)$usec + (float)$sec);
    	}
    }
     
     
    function safe_var_export($var)
    {
    	if ( ! is_array($var))
    	{
    		return var_export($var, true);
    	}
     
    	foreach ($var as $key => $data)
    	{
    		if (('GLOBALS' == $key) || ($data == $var))
    		{
    			$var[$key] = 'RECURSION';
    			continue;
    		}
    	}
     
    	return var_export($var, true);
    }
    Ceci est mon dernier mot.
    Pour l'instant.
    Il faut être passionné quand même!
    Alors si une âme charitable veut bien m'aider...............?
    L' ignorance, toujours mène à la servitude.

Discussions similaires

  1. Problème de connexion à une base de donnée MySQL
    Par casho dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 27/06/2007, 14h04
  2. Réponses: 5
    Dernier message: 18/05/2007, 14h34
  3. [VB 2003] Problème de connexion à une base de donnée Access
    Par beegees dans le forum Windows Forms
    Réponses: 2
    Dernier message: 21/04/2007, 20h12
  4. problème de connexion à une base de données
    Par dali_dragon dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 29/11/2006, 19h25
  5. [ODBC] [DB2] Problème de connexion à une base de données sur un as400 via PHP sous Linux
    Par boo64 dans le forum PHP & Base de données
    Réponses: 16
    Dernier message: 19/04/2006, 09h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo