3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * SAE Mysql服务 * * 支持主从分离 * * @author Easychen <easychen@gmail.com> * @version $Id$ * @package sae * */ /** * Sae Mysql Class * * <code> * <?php * $mysql = new SaeMysql(); * * $sql = "SELECT * FROM `user` LIMIT 10"; * $data = $mysql->getData( $sql ); * $name = strip_tags( $_REQUEST['name'] ); * $age = intval( $_REQUEST['age'] ); * $sql = "INSERT INTO `user` ( `name` , `age` , `regtime` ) VALUES ( '" . $mysql->escape( $name ) . "' , '" . intval( $age ) . "' , NOW() ) "; * $mysql->runSql( $sql ); * if( $mysql->errno() != 0 ) * { * die( "Error:" . $mysql->errmsg() ); * } * * $mysql->closeDb(); * ?> * </code> * * @package sae * @author EasyChen * */ class SaeMysql extends SaeObject { /** * 构造函数 * * @param bool $do_replication 是否支持主从分离,true:支持,false:不支持,默认为true * @return void * @author EasyChen */ function __construct( $do_replication = true ) { $this->port = 3307; $this->host = '.rdc.sae.sina.com.cn'; $this->accesskey = SAE_ACCESSKEY; $this->secretkey = SAE_SECRETKEY; $this->appname = 'app_' . $_SERVER['HTTP_APPNAME']; //set default charset as utf8 $this->charset = 'UTF8'; $this->do_replication = $do_replication; } /** * 设置keys * * 当需要连接其他APP的数据库时使用 * * @param string $akey AccessKey * @param string $skey SecretKey * @return void * @author EasyChen */ public function setAuth( $akey , $skey ) { $this->accesskey = $akey; $this->secretkey = $skey; } /** * 设置Mysql服务器端口 * * 当需要连接其他APP的数据库时使用 * * @param string $port * @return void * @author EasyChen */ public function setPort( $port ) { $this->port = 3307; $this->host = '.rdc.sae.sina.com.cn'; } /** * 设置Appname * * 当需要连接其他APP的数据库时使用 * * @param string $appname * @return void * @author EasyChen */ public function setAppname( $appname ) { $this->appname = 'app_' . $appname; } /** * 设置当前连接的字符集 , 必须在发起连接之前进行设置 * * @param string $charset 字符集,如GBK,GB2312,UTF8 * @return void */ public function setCharset( $charset ) { return $this->set_charset( $charset ); } /** * 同setCharset,向前兼容 * * @param string $charset * @return void * @ignore */ public function set_charset( $charset ) { $this->charset = $charset; } /** * 运行Sql语句,不返回结果集 * * @param string $sql * @return mysqli_result|bool */ public function runSql( $sql ) { return $this->run_sql( $sql ); } /** * 同runSql,向前兼容 * * @param string $sql * @return bool * @author EasyChen * @ignore */ public function run_sql( $sql ) { $this->last_sql = $sql; $dblink = $this->db_write(); if ($dblink === false) { return false; } $ret = mysqli_query( $dblink, $sql ); $this->save_error( $dblink ); return $ret; } /** * 运行Sql,以多维数组方式返回结果集 * * @param string $sql * @return array 成功返回数组,失败时返回false * @author EasyChen */ public function getData( $sql ) { return $this->get_data( $sql ); } /** * 同getData,向前兼容 * * @ignore */ public function get_data( $sql ) { $this->last_sql = $sql; $data = Array(); $i = 0; $dblink = $this->do_replication ? $this->db_read() : $this->db_write(); if ($dblink === false) { return false; } $result = mysqli_query( $dblink , $sql ); $this->save_error( $dblink ); if (is_bool($result)) { return $result; } else { while( $Array = mysqli_fetch_array( $result, MYSQL_ASSOC ) ) { $data[$i++] = $Array; } } mysqli_free_result($result); if( count( $data ) > 0 ) return $data; else return NULL; } /** * 运行Sql,以数组方式返回结果集第一条记录 * * @param string $sql * @return array 成功返回数组,失败时返回false * @author EasyChen */ public function getLine( $sql ) { return $this->get_line( $sql ); } /** * 同getLine,向前兼容 * * @param string $sql * @return array * @author EasyChen * @ignore */ public function get_line( $sql ) { $data = $this->get_data( $sql ); if ($data) { return @reset($data); } else { return false; } } /** * 运行Sql,返回结果集第一条记录的第一个字段值 * * @param string $sql * @return mixxed 成功时返回一个值,失败时返回false * @author EasyChen */ public function getVar( $sql ) { return $this->get_var( $sql ); } /** * 同getVar,向前兼容 * * @param string $sql * @return array * @author EasyChen * @ignore */ public function get_var( $sql ) { $data = $this->get_line( $sql ); if ($data) { return $data[ @reset(@array_keys( $data )) ]; } else { return false; } } /** * 同mysqli_affected_rows函数 * * @return int 成功返回行数,失败时返回-1 * @author Elmer Zhang */ public function affectedRows() { $result = isset($this->db_write) ? mysqli_affected_rows( $this->db_write ) : -1; return $result; } /** * 同mysqli_insert_id函数 * * @return int 成功返回last_id,失败时返回false * @author EasyChen */ public function lastId() { return $this->last_id(); } /** * 同lastId,向前兼容 * * @return int * @author EasyChen * @ignore */ public function last_id() { $result = mysqli_insert_id( $this->db_write( false ) ); return $result; } /** * 关闭数据库连接 * * @return bool * @author EasyChen */ public function closeDb() { return $this->close_db(); } /** * 同closeDb,向前兼容 * * @return bool * @author EasyChen * @ignore */ public function close_db() { if( isset( $this->db_read ) ) @mysqli_close( $this->db_read ); if( isset( $this->db_write ) ) @mysqli_close( $this->db_write ); } /** * 同mysqli_real_escape_string * * @param string $str * @return string * @author EasyChen */ public function escape( $str ) { if( isset($this->db_read) ) { $db = $this->db_read; } elseif( isset($this->db_write) ) { $db = $this->db_write; } else { $db = $this->db_read(); } return mysqli_real_escape_string( $db , $str ); } /** * 返回错误码 * * * @return int * @author EasyChen */ public function errno() { return $this->errno; } /** * 返回错误信息 * * @return string * @author EasyChen */ public function error() { return $this->error; } /** * 返回错误信息,error的别名 * * @return string * @author EasyChen */ public function errmsg() { return $this->error(); } /** * @ignore */ private function connect( $is_master = true ) { if ($this->port == 0) { $this->error = 13048; $this->errno = 'Not Initialized'; return false; } if( $is_master ) $host = 'w' . $this->host; else $host = 'r' . $this->host; $db = mysqli_init(); mysqli_options($db, MYSQLI_OPT_CONNECT_TIMEOUT, 5); if( !mysqli_real_connect( $db, $host , $this->accesskey , $this->secretkey , $this->appname , $this->port ) ) { $this->error = mysqli_connect_error(); $this->errno = mysqli_connect_errno(); return false; } mysqli_set_charset( $db, $this->charset); return $db; } /** * @ignore */ private function db_read() { if( isset( $this->db_read ) && mysqli_ping( $this->db_read ) ) { return $this->db_read; } else { if( !$this->do_replication ) return $this->db_write(); else { $this->db_read = $this->connect( false ); return $this->db_read; } } } /** * @ignore */ private function db_write( $reconnect = true ) { if( isset( $this->db_write ) && ( $reconnect == false || mysqli_ping( $this->db_write ) ) ) { return $this->db_write; } else { $this->db_write = $this->connect( true ); return $this->db_write; } } /** * @ignore */ private function save_error($dblink) { $this->error = mysqli_error($dblink); $this->errno = mysqli_errno($dblink); } private $error; private $errno; private $last_sql; } //Documentation generated on Tue, 25 Feb 2014 21:24:45 +0800 by phpDocumentor 1.4.3 $mysql = new SaeMysql();//sae内部类链接数据 $num = "SELECT * FROM `message` "; $mysql->runSql($num); $no=$mysql->affectedRows();//获取行数 echo $no; printf($no);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0110.01118.43
8.3.50.0160.00321.95
8.3.40.0120.00319.01
8.3.30.0070.00719.16
8.3.20.0030.00620.16
8.3.10.0060.00321.79
8.3.00.0000.00822.40
8.2.180.0120.00916.85
8.2.170.0100.01022.96
8.2.160.0040.01122.21
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0040.00417.75
8.2.110.0070.00319.39
8.2.100.0030.00917.90
8.2.90.0040.00419.31
8.2.80.0000.00817.97
8.2.70.0060.00317.63
8.2.60.0080.00017.80
8.2.50.0070.00318.09
8.2.40.0060.00320.61
8.2.30.0000.00819.52
8.2.20.0030.00517.86
8.2.10.0000.00817.88
8.2.00.0040.00417.70
8.1.280.0140.00025.92
8.1.270.0040.00422.19
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00322.52
8.1.230.0000.01117.77
8.1.220.0000.00817.74
8.1.210.0030.00518.77
8.1.200.0080.00317.48
8.1.190.0000.00917.35
8.1.180.0050.00318.10
8.1.170.0050.00318.76
8.1.160.0000.00720.65
8.1.150.0040.00418.66
8.1.140.0050.00317.41
8.1.130.0020.00517.86
8.1.120.0000.00717.45
8.1.110.0000.00817.36
8.1.100.0030.00517.30
8.1.90.0050.00517.47
8.1.80.0040.00417.47
8.1.70.0050.00217.47
8.1.60.0030.00517.59
8.1.50.0090.00017.45
8.1.40.0030.00517.43
8.1.30.0000.00817.59
8.1.20.0000.00817.69
8.1.10.0040.00417.59
8.1.00.0080.00017.42
8.0.300.0040.00418.77
8.0.290.0040.00417.00
8.0.280.0000.00818.50
8.0.270.0030.00317.33
8.0.260.0030.00317.05
8.0.250.0070.00017.11
8.0.240.0000.00817.07
8.0.230.0050.00317.12
8.0.220.0050.00216.93
8.0.210.0040.00417.06
8.0.200.0020.00517.16
8.0.190.0000.00917.11
8.0.180.0020.00517.10
8.0.170.0030.00516.95
8.0.160.0000.00817.07
8.0.150.0000.00716.93
8.0.140.0040.00417.02
8.0.130.0000.00613.44
8.0.120.0080.00017.02
8.0.110.0000.00717.04
8.0.100.0060.00317.05
8.0.90.0070.00016.94
8.0.80.0060.00917.02
8.0.70.0030.00517.06
8.0.60.0000.00817.07
8.0.50.0040.00416.97
8.0.30.0110.00817.03
8.0.20.0130.00517.40
8.0.10.0000.00916.97
8.0.00.0100.00816.74
7.4.330.0070.00015.00
7.4.320.0040.00416.52
7.4.300.0040.00416.61
7.4.290.0030.00316.47
7.4.280.0000.00716.53
7.4.270.0030.00316.43
7.4.260.0070.00016.51
7.4.250.0000.00816.38
7.4.240.0020.00516.62
7.4.230.0040.00416.71
7.4.220.0060.01216.54
7.4.210.0080.00916.62
7.4.200.0070.00016.46
7.4.190.0000.00716.42
7.4.160.0130.01016.42
7.4.150.0120.00617.40
7.4.140.0090.00817.86
7.4.130.0090.00816.71
7.4.120.0150.00516.58
7.4.110.0130.01016.38
7.4.100.0090.00916.69
7.4.90.0130.01016.63
7.4.80.0130.00719.39
7.4.70.0150.00316.62
7.4.60.0110.00716.52
7.4.50.0040.00416.51
7.4.40.0060.00922.77
7.4.30.0080.00816.41
7.4.00.0030.01215.23
7.3.330.0030.00313.26
7.3.320.0050.00013.36
7.3.310.0050.00216.20
7.3.300.0030.00316.36
7.3.290.0030.01716.39
7.3.280.0080.00916.38
7.3.270.0090.00917.40
7.3.260.0100.00716.52
7.3.250.0140.00316.46
7.3.240.0120.00616.57
7.3.230.0140.00416.44
7.3.210.0030.01316.36
7.3.200.0130.00319.39
7.3.190.0030.01716.55
7.3.180.0090.00616.43
7.3.170.0100.00616.50
7.3.160.0110.00616.48
7.3.120.0070.00714.68
7.3.10.0000.01516.47
7.3.00.0090.00616.41
7.2.330.0070.01116.48
7.2.320.0160.00616.63
7.2.310.0070.01016.66
7.2.300.0040.01216.69
7.2.290.0120.00916.43
7.2.130.0060.01216.64
7.2.120.0030.01416.80
7.2.110.0090.00616.62
7.2.100.0000.01116.48
7.2.90.0070.01116.86
7.2.80.0100.00616.70
7.2.70.0070.01016.76
7.2.60.0040.00816.61
7.2.50.0040.01116.79
7.2.40.0130.00016.75
7.2.30.0060.00316.59
7.2.20.0070.01016.79
7.2.10.0000.01016.43
7.2.00.0060.01316.74
7.1.250.0030.01215.41
7.1.200.0090.00315.29
7.1.70.0030.00617.08
7.1.60.0100.01619.82
7.1.50.0110.01416.86
7.1.00.0070.07022.44
7.0.200.0080.00316.62
7.0.140.0100.07021.95
7.0.100.0430.07720.02
7.0.90.0470.07020.05
7.0.80.0430.07320.05
7.0.70.0200.04720.05
7.0.60.0200.07720.14
7.0.50.0470.07320.41
7.0.40.0030.06720.10
7.0.30.0000.07320.14
7.0.20.0070.07320.15
7.0.10.0130.08020.04
7.0.00.0130.07320.17
5.6.280.0070.07021.05
5.6.250.0100.07720.56
5.6.240.0170.06720.73
5.6.230.0100.07720.75
5.6.220.0170.06720.71
5.6.210.0030.08320.53
5.6.200.0070.08721.20
5.6.190.0030.07721.10
5.6.180.0170.06721.08
5.6.170.0070.07021.14
5.6.160.0030.07021.19
5.6.150.0030.08321.09
5.6.140.0030.07321.11
5.6.130.0070.08321.14
5.6.120.0100.07021.11
5.6.110.0070.08721.11
5.6.100.0070.08321.01
5.6.90.0070.05021.11
5.6.80.0000.08720.62
5.6.70.0070.08020.46
5.6.60.0070.06720.53
5.6.50.0100.07020.53
5.6.40.0270.05320.59
5.6.30.0070.07020.39
5.6.20.0070.06020.47
5.6.10.0100.07320.46
5.6.00.0070.08020.48
5.5.380.0070.08020.46
5.5.370.0130.07320.46
5.5.360.0030.06020.42
5.5.350.0030.07020.50
5.5.340.0070.08020.80
5.5.330.0130.07720.83
5.5.320.0130.07320.99
5.5.310.0070.08020.86
5.5.300.0100.08020.84
5.5.290.0230.05320.89
5.5.280.0030.04320.93
5.5.270.0170.07320.77
5.5.260.0070.09020.82
5.5.250.0130.07720.80
5.5.240.0200.06720.21
5.5.230.0130.06720.30
5.5.220.0070.08320.23
5.5.210.0070.06720.08
5.5.200.0070.08020.28
5.5.190.0070.07320.19
5.5.180.0030.08020.30
5.5.160.0070.07720.21
5.5.150.0030.08320.14
5.5.140.0070.07720.24
5.5.130.0130.07020.18
5.5.120.0170.06020.31
5.5.110.0100.07720.31
5.5.100.0200.06320.18
5.5.90.0070.08020.13
5.5.80.0130.06720.22
5.5.70.0030.04020.06
5.5.60.0100.06020.12
5.5.50.0170.06719.99
5.5.40.0100.05020.17
5.5.30.0100.07020.08
5.5.20.0070.04720.11
5.5.10.0170.06720.02
5.5.00.0100.07720.16
5.4.450.0100.04319.23
5.4.440.0130.07719.39
5.4.430.0100.07319.23
5.4.420.0170.04719.50
5.4.410.0170.06319.14
5.4.400.0070.07018.95
5.4.390.0070.07019.05
5.4.380.0030.08319.05
5.4.370.0000.08018.85
5.4.360.0030.07019.04
5.4.350.0100.04019.13
5.4.340.0030.08319.21
5.4.320.0030.05319.14
5.4.310.0070.04319.09
5.4.300.0070.06718.87
5.4.290.0030.07718.84
5.4.280.0030.04019.09
5.4.270.0070.07718.90
5.4.260.0030.07018.90
5.4.250.0030.06719.20
5.4.240.0030.07718.86
5.4.230.0170.05319.03
5.4.220.0130.05718.87
5.4.210.0130.06718.84
5.4.200.0100.07019.16
5.4.190.0100.07019.02
5.4.180.0070.08319.11
5.4.170.0070.05318.84
5.4.160.0130.06318.86
5.4.150.0000.08019.11
5.4.140.0000.07016.45
5.4.130.0070.04016.32
5.4.120.0030.08016.41
5.4.110.0100.07716.38
5.4.100.0070.05016.49
5.4.90.0070.03316.52
5.4.80.0100.06016.51
5.4.70.0130.06316.43
5.4.60.0070.06716.50
5.4.50.0100.05716.53
5.4.40.0100.06316.53
5.4.30.0070.07016.52
5.4.20.0130.06316.41
5.4.10.0130.04716.36
5.4.00.0100.06715.84
5.3.290.0030.07314.67
5.3.280.0030.08014.79
5.3.270.0130.07014.70
5.3.260.0070.05714.68
5.3.250.0070.06314.77
5.3.240.0130.04714.66
5.3.230.0070.06714.77
5.3.220.0030.05014.62
5.3.210.0030.06014.75
5.3.200.0100.07014.75
5.3.190.0100.06714.64
5.3.180.0030.07714.69
5.3.170.0030.08014.75
5.3.160.0100.03714.67
5.3.150.0000.06314.57
5.3.140.0000.08314.61
5.3.130.0070.07014.69
5.3.120.0100.04314.71
5.3.110.0130.07014.59
5.3.100.0070.08014.20
5.3.90.0200.05714.05
5.3.80.0100.07314.04
5.3.70.0000.04713.98
5.3.60.0100.06714.01
5.3.50.0000.07314.07
5.3.40.0070.03314.07
5.3.30.0100.04713.86
5.3.20.0170.05713.88
5.3.10.0100.07313.66
5.3.00.0000.06013.64

preferences:
35.07 ms | 401 KiB | 5 Q