【问题标题】:What Exact Version PHP & MySQL from PHP script?PHP 脚本中 PHP 和 MySQL 的确切版本是什么?
【发布时间】:2015-08-16 05:39:51
【问题描述】:

我需要知道用于 magento 安装检查的 PHP 和 MySQL 的确切版本

我从这里获得 MySQl 版本:

//Test What Exact Version PHP & MySQL

echo "<h2>Exact Version PHP & MySQL: </h2>";

$mysql = mysqli_connect('localhost', 'root', ''); 
/* Test the MySQL connection */
if (mysqli_connect_errno()) {
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}

/* Print the MySQL server version */
printf("MySQL server version: %s\n", mysqli_get_server_info($mysql));

/* Close the MySQL connection */
mysqli_close($mysql);

但是我怎样才能得到准确的 PHP 版本

【问题讨论】:

    标签: php mysql apache server version


    【解决方案1】:

    http://php.net/manual/en/function.phpversion.php

    printf("PHP 版本:%s\n", phpversion());

    http://php.net/manual/en/reserved.constants.php#reserved.constants.core

    只是:

    printf("PHP 版本:%s\n", PHP_VERSION);

    【讨论】:

      【解决方案2】:

      你可以用 PHP 做到这一点,只需使用以下脚本,它就会在页面上显示你所有的 PHP 信息:

      <?php
      phpinfo();
      ?>
      

      或者,如果您只想要 PHP 版本,那么:

      <?php
      echo "PHP version is: " . phpversion();
      ?>
      

      【讨论】:

        【解决方案3】:

        php 中有两个函数可以获取 PHP 和 MySql 的准确版本。

        • 适用于 PHP 版本

          phpversion();
          
        • MySql 版本

          mysql_get_server_info();
          

        参考:

        http://php.net/manual/en/function.phpversion.php

        http://php.net/manual/en/function.mysql-get-server-info.php

        【讨论】:

        • 关于mysql_get_server_info();:此扩展在 PHP 5.5.0 中已被弃用,并在 PHP 7.0.0 中被删除。相反,应该使用 MySQLi 或 PDO_MySQL 扩展。
        【解决方案4】:

        另一种检查准确版本 PHP 和 MySQL 以安装 magento 的方法

        extension_check(array( 
            'curl',
            'dom', 
            'gd', 
            'hash',
            'iconv',
            'mcrypt',
            'pcre', 
            'pdo', 
            'pdo_mysql', 
            'simplexml'
        ));
        function extension_check($extensions) {
            $fail = '';
            $pass = '';
        
            if(version_compare(phpversion(), '5.2.0', '<')) {
                $fail .= '<li>You need<strong> PHP 5.2.0</strong> (or greater;<strong>Current Version:'.phpversion().')</strong></li>';
            }
            else {
                $pass .='<li>You have<strong> PHP 5.2.0</strong> (or greater; <strong>Current Version:'.phpversion().')</strong></li>';
            }
            if(!ini_get('safe_mode')) {
                $pass .='<li>Safe Mode is <strong>off</strong></li>';
                preg_match('/[0-9]\.[0-9]+\.[0-9]+/', shell_exec('mysql -V'), $version);
        
                if(version_compare($version[0], '4.1.20', '<')) {
                    $fail .= '<li>You need<strong> MySQL 4.1.20</strong> (or greater; <strong>Current Version:.'.$version[0].')</strong></li>';
                }
                else {
                    $pass .='<li>You have<strong> MySQL 4.1.20</strong> (or greater; <strong>Current Version:'.$version[0].')</strong></li>';
                }
            }
            else { $fail .= '<li>Safe Mode is <strong>on</strong></li>';  }
            foreach($extensions as $extension) {
                if(!extension_loaded($extension)) {
                    $fail .= '<li> You are missing the <strong>'.$extension.'</strong> extension</li>';
                }
                else{   $pass .= '<li>You have the <strong>'.$extension.'</strong> extension</li>';
                }
            }
        
            if($fail) {
                echo '<p><strong>Your server does not meet the following requirements in order to install Magento.</strong>';
                echo '<br>The following requirements failed, please contact your hosting provider in order to receive assistance with meeting the system requirements for Magento:';
                echo '<ul>'.$fail.'</ul></p>';
                echo 'The following requirements were successfully met:';
                echo '<ul>'.$pass.'</ul>';
            } else {
                echo '<p><strong>Congratulations!</strong> Your server meets the requirements for Magento.</p>';
                echo '<ul>'.$pass.'</ul>';
            }
        }
        
        
        Test What Exact Version PHP & MySQL
        
            echo "<h2>Exact Version PHP & MySQL: </h2>";
            printf("PHP version: %s\n", PHP_VERSION); 
        
            ##### Without DB Access 
            ob_start(); 
            phpinfo(INFO_MODULES); 
            $info = ob_get_contents(); 
            ob_end_clean(); 
            $info = stristr($info, 'Client API version'); 
            preg_match('/[1-9].[0-9].[1-9][0-9]/', $info, $match); 
            $gd = $match[0]; 
            echo '</br>MySQL:  '.$gd.' <br />';
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-10-12
          • 1970-01-01
          • 2013-12-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-04-30
          • 1970-01-01
          相关资源
          最近更新 更多