kenken999/php
0
1<?php2 3/////////////////////////////////////////////////////////////////////////////4// PHPRunner connect proxy5//6define('RUNNER_VERSION', '5.1');7/////////////////////////////////////////////////////////////////////////////8 9// check if the mysqli extension is enabled10$use_mysqli_ext = function_exists('mysqli_connect');11 12ini_set("display_errors","1");13ini_set("display_startup_errors","1");14 15$host = @$_REQUEST["host"];16$login = @$_REQUEST["login"];17$pwd = @$_REQUEST["pwd"];18$ssl = @$_REQUEST["ssl"];19$port = @$_REQUEST["port"];20$db = @$_REQUEST["db"];21$todo = @$_REQUEST["todo"];22 23 24$mysqliFieldTypesMap = array(250 => "decimal", //MYSQL_TYPE_DECIMAL,261 => "tiny", //MYSQL_TYPE_TINY,272 => "short", //MYSQL_TYPE_SHORT,283 => "int", //MYSQL_TYPE_LONG,294 => "float", //MYSQL_TYPE_FLOAT,305 => "double", //MYSQL_TYPE_DOUBLE,316 => "", //MYSQL_TYPE_NULL,327 => "timestamp", //MYSQL_TYPE_TIMESTAMP,338 => "int", //MYSQL_TYPE_LONGLONG,349 => "int", //MYSQL_TYPE_INT24,3510 => "date", //MYSQL_TYPE_DATE,3611 => "time", //MYSQL_TYPE_TIME,3712 => "datetime", //MYSQL_TYPE_DATETIME,3813 => "int", //MYSQL_TYPE_YEAR,3914 => "date", //MYSQL_TYPE_NEWDATE,4015 => "varchar", //MYSQL_TYPE_VARCHAR,4116 => "tiny", //MYSQL_TYPE_BIT,4217 => "timestamp", //MYSQL_TYPE_TIMESTAMP2,4318 => "datetime", //MYSQL_TYPE_DATETIME2,4419 => "time", //MYSQL_TYPE_TIME2,45246 => "decimal", //MYSQL_TYPE_NEWDECIMAL=246,46247 => "varchar", //MYSQL_TYPE_ENUM=247,47248 => "varchar", //MYSQL_TYPE_SET=248,48249 => "blob", //MYSQL_TYPE_TINY_BLOB=249,49250 => "blob", //MYSQL_TYPE_MEDIUM_BLOB=250,50251 => "blob", //MYSQL_TYPE_LONG_BLOB=251,51252 => "blob", //MYSQL_TYPE_BLOB=252,52253 => "varchar", //MYSQL_TYPE_VAR_STRING=253,53254 => "varchar", //MYSQL_TYPE_STRING=254,54255 => "blob" //MYSQL_TYPE_GEOMETRY=25555);56 57 58if( $todo == "connect" || $todo == "schema" )59{60 $conn = db_connect($host, $login, $pwd, $port, $ssl);61 if( !$conn )62 {63 echo "<div><font color=red>".db_error($conn)."</font></div>";64 $todo = "";65 }66}67 68if( $todo == "schema" )69{70 if( !select_db($db, $conn) )71 {72 echo "<div><font color=red>".db_error($conn)."</font></div>";73 $todo = "connect";74 }75 else76 {77 show_schema();78 exit();79 }80}81 82if( !$todo || $todo == "connect" )83{84?>85<html><body>86<form method="get" name="mainform" action="phprunner.php">87<input type="Hidden" name="todo" value="connect">88<table cellspacing="2" cellpadding="2" border="0">89<tr>90 <td nowrap>Server address</td>91 <td><input type="Text" name="host" value="<?php if(!$host) echo "localhost"; else echo htmlspecialchars($host);?>"></td>92</tr>93<tr>94 <td colspan=2> <label><input type="Checkbox" name="ssl" <?php echo($ssl ? "checked" : ""); ?>>SSL connection</label></td>95</tr>96<tr>97 <td nowrap>Username</td>98 <td><input type="Text" name="login" value="<?php echo htmlspecialchars($login);?>"></td>99</tr>100<tr>101 <td nowrap>Password</td>102 <td><input type="Text" name="pwd" value="<?php echo htmlspecialchars($pwd);?>"></td>103</tr>104<tr>105 <td nowrap>Port (if not 3306)</td>106 <td><input type="Text" name="port" value="<?php echo htmlspecialchars($port);?>"></td>107</tr>108<tr>109 <td></td>110 <td><input type="button" value="Connect" onclick="mainform.submit();"></td>111</tr>112<?php113if( $todo == "connect" )114{115?>116<tr>117 <td nowrap>Database</td>118 <td>119<?php120 $dblist = get_dbs_list($conn);121 if( $dblist && $row = db_fetch_array($dblist) )122 {123?>124 <select name="db">125<?php126 while(true)127 {128 echo "<option value=\"".htmlspecialchars( $row["Database"] )."\">".htmlspecialchars( $row["Database"] )."</option>";129 if( !($row = db_fetch_array($dblist)) )130 break;131 }132?>133 </select>134<?php135 }136 else137 {138?>139 <input type="Text" name="db" size=30 maxlength=100 value="<?php echo htmlspecialchars($db);?>">140<?php141 }142?>143</td>144</tr>145<?php146 147?>148<tr>149 <td></td>150 <td><input type="button" value="Show schema" onclick="if(this.form.db.tagName=='INPUT' && this.form.db.value=='') {alert('Enter your database name first.'); return false;} this.form.todo.value='schema'; this.form.submit();"></td>151</tr>152<?php153 }154?>155</table>156</form>157</body></html>158<?php159 return;160}161 162// process PHPRunner 5.1 commands163 164if( $todo == 'version' )165{166 echo RUNNER_VERSION;167 return;168}169 170if( $todo == "exec5" )171{172 exec5();173 return;174}175 176if( $todo == "query5" )177{178 query5();179 return;180}181 182if( $todo == "testconnect5" )183{184 testconnect5();185 return;186}187 188// process PHPRunner 5.0 commands189$conn = db_connect($host, $login, $pwd, $port, $ssl);190if(!$conn)191{192 echo htmlspecialchars( db_error($conn) );193 exit();194}195 196if( $todo == "testconnect" )197{198 echo "connected ok";199 return;200}201 202if( $todo == "exec" )203{204 if( $db && !select_db($db, $conn) )205 {206 echo htmlspecialchars( db_error($conn) );207 return;208 }209 $res = db_query( $_REQUEST["sql"], $conn );210 if( !$res )211 echo htmlspecialchars( db_error($conn) );212 else213 echo "1";214 return;215}216 217header("Content-type: text/xml");218 219if( $todo == "dbs" )220{221 $dblist = get_dbs_list($conn);222 echo '<?xml version="1.0" standalone="yes" ?>';223 echo "<databases>";224 while( $row = db_fetch_array($dblist) )225 echo "<database name=\"".htmlspecialchars( $row["Database"] )."\" />";226 echo "</databases>";227}228else if( $todo == "queryfields" )229{230 select_db($db, $conn) or showerror($conn);231 $sql = @$_REQUEST["sql"];232 if( !$sql )233 return;234 235 $sql.= " limit 0,0";236 $res = db_query($sql, $conn);237 238 echo '<?xml version="1.0" standalone="yes" ?>';239 echo "<fields>";240 ptintQueryFieldsInfo($res, $conn);241 echo "</fields>";242}243else if( $todo == "tables" )244{245 select_db($db, $conn) or showerror($conn);246 $tablist = get_tables_list($db, $conn);247 echo '<?xml version="1.0" standalone="yes" ?>';248 echo "<tables>";249 while( $row = db_fetch_numarray($tablist) )250 {251 echo "<table name=\"".htmlspecialchars( $row[0] )."\" />";252 }253 echo "</tables>";254}255else if( $todo == "tablefields" )256{257 $table = @$_REQUEST["table"];258 if( !$table )259 return;260 261 select_db($db, $conn) or showerror($conn);262 echo '<?xml version="1.0" standalone="yes" ?>';263 showtablefields($table);264}265else if( $todo == "queryvalues" )266{267 select_db($db, $conn) or showerror($conn);268 $sql = @$_REQUEST["sql"];269 if( !$sql )270 return;271 272 $sql.=" limit 0,200";273 $res = db_query($sql, $conn);274 if(!$res)275 {276 echo db_error($conn);277 return;278 }279 280 echo '<?xml version="1.0" standalone="yes" ?>';281 if( getFieldsNumberInLastQuery($res, $conn) == 1 )282 {283 echo "<values>";284 while( $row = db_fetch_numarray($res) )285 {286 echo "<value>".htmlspecialchars( $row[0] )."</value>";287 }288 echo "</values>";289 }290 else291 {292 echo "<rows>\r\n";293 while( $row = db_fetch_numarray($res) )294 {295 echo "<row>";296 for($i = 0; $i < count($row); $i++)297 {298 echo "<value>".htmlspecialchars( $row[$i] )."</value>";299 }300 echo "</row>\r\n";301 }302 echo "</rows>";303 }304}305else if( $todo == "queryvaluesraw" )306{307 select_db($db, $conn) or showerror($conn);308 $sql = @$_REQUEST["sql"];309 if( !$sql )310 return;311 312 $res = db_query($sql, $conn);313 if(!$res)314 {315 echo db_error($conn);316 return;317 }318 319 echo '<?xml version="1.0" standalone="yes" ?>';320 echo "<rows>\r\n";321 322 echo "<row>\r\n";323 printXMLFieldNames($res);324 echo "</row>\r\n";325 326 while( $row = db_fetch_numarray($res) )327 {328 echo "<row>\r\n";329 for($i = 0; $i < count($row); $i++)330 {331 echo "<value>".htmlspecialchars( $row[$i] )."</value>\r\n";332 }333 echo "</row>\r\n";334 }335 echo "</rows>\r\n";336}337else if( $todo == "queryvaluesstr" )338{339 select_db($db, $conn) or showerror($conn);340 $sql = @$_REQUEST["sql"];341 if( !$sql )342 return;343 $res = db_query($sql, $conn);344 if(!$res)345 {346 echo db_error($conn);347 return;348 }349 350 $binfields = array();351 $fieldNames = array();352 for($i = 0; $i < getFieldsNumberInLastQuery($res, $conn); $i++)353 {354 $finfo = getFieldInfo( $res, $i );355 356 $flags = strtolower( $finfo["flags"] );357 if( strpos($flags, "binary") !== false )358 $binfields[] = $i;359 360 $fieldNames[] = $finfo["name"];361 }362 363 echo '<?xml version="1.0" standalone="yes" ?>';364 echo "<rows>\r\n";365 echo "<row>\r\n";366 foreach($fieldNames as $fName)367 {368 echo "<value>".htmlspecialchars($fName)."</value>\r\n";369 }370 echo "</row>\r\n";371 372 while( $row = db_fetch_numarray($res) )373 {374 echo "<row>\r\n";375 for($i = 0; $i < count($row); $i++)376 {377 $ret = array_search($i, $binfields);378 if( $ret === FALSE || $ret === NULL )379 echo "<value>".htmlspecialchars( $row[$i] )."</value>\r\n";380 else381 {382 if ( strlen($row[$i]) == 0 )383 echo "<value>NULL</value>\r\n";384 else385 echo "<value>0x".bin2hex( $row[$i] )."</value>\r\n";386 }387 }388 echo "</row>\r\n";389 }390 echo "</rows>\r\n";391}392 393 394/**395 * Get query field data396 * @param object res A result set identifier397 * @param number fieldnr The field number398 * @return array399 */400function getFieldInfo($res, $fieldnr)401{402 global $use_mysqli_ext, $mysqliFieldTypesMap;403 404 if( $use_mysqli_ext )405 {406 $finfo = mysqli_fetch_field_direct($res, $fieldnr);407 $fieldType = @$mysqliFieldTypesMap[$finfo->type];408 $strFlags = "";409 if($finfo->flags & 512)410 $strFlags .= "auto_increment ";411 if($finfo->flags & 2)412 $strFlags .= "primary ";413 if($finfo->flags & 1)414 $strFlags .= "not_null ";415 if($finfo->flags & 128)416 $strFlags .= "binary ";417 return array( "name" => $finfo->name, "flags" => $strFlags, "type" => $fieldType, "length" => $finfo->length );418 }419 420 return array("name" => mysql_field_name($res, $fieldnr), "flags" => mysql_field_flags($res, $fieldnr), "type" => mysql_field_type($res, $fieldnr), "length" => mysql_field_len($res, $fieldnr));421}422 423/**424 * @param object $res A result set identifier425 */426function printXMLFieldNames($res)427{428 global $use_mysqli_ext;429 430 if( !$use_mysqli_ext )431 {432 for($i = 0; $i < mysql_num_fields($res); $i++)433 {434 echo "<value>".htmlspecialchars( mysql_field_name($res, $i) )."</value>\r\n";435 }436 return;437 }438 439 while( $finfo = mysqli_fetch_fields($res) )440 {441 echo "<value>".htmlspecialchars( $finfo["name"] )."</value>\r\n";442 }443}444 445/**446 * @param object res A result set identifier447 * @param mixed conn A link identifier448 */449function ptintQueryFieldsInfo($res, $conn)450{451 for($i = 0; $i < getFieldsNumberInLastQuery($res, $conn); $i++)452 {453 $finfo = getFieldInfo( $res, $i );454 455 $flags = strtolower( $finfo['flags']);456 457 $type = $finfo['type'];458 if( $type == "blob" && strpos($flags, "binary") === false )459 $type = "text";460 461 echo "<field name=\"".htmlspecialchars( $finfo['name'] )."\" type=\"".htmlspecialchars($type)."\" size=\"".htmlspecialchars( $finfo['length'] )."\" ";462 463 if( !(strpos($flags, "auto_increment") === false) )464 echo "auto_increment=\"auto_increment\" ";465 if( !(strpos($flags, "primary_key") === false) )466 echo "key=\"PRI\" ";467 if( !(strpos($flags, "not_null") === false) )468 echo "null=\"\" ";469 else470 echo "null=\"YES\" ";471 echo " />";472 }473}474 475 476function showtablefields($table)477{478 global $conn;479 $fields = db_query("SHOW fields FROM `".$table."`", $conn);480 if( !$fields )481 {482 echo db_error($conn);483 exit();484 }485 echo "<fields>";486 while( $field = db_fetch_array($fields) )487 {488 $attr = array();489 $attr["name"] = $field["Field"];490 $type = $field["Type"];491 // remove type modifiers492 if( substr($type, 0, 4) == "tiny" )493 $type = substr($type, 4);494 else if( substr($type, 0, 5) == "small" )495 $type = substr($type, 5);496 else if( substr($type, 0, 6) == "medium" )497 $type = substr($type, 6);498 else if( substr($type, 0, 3) == "big" )499 $type = substr($type, 3);500 else if(substr($type, 0, 4) == "long")501 $type = substr($type, 4);502 if( substr($type, 0, 4) == "enum")503 {504 $attr["values"] = substr($type, 5, strlen($type) - 6);505 $attr["type"] = "enum";506 }507 else if( substr($type, 0, 3) == "set" )508 {509 $attr["values"] = substr($type, 4, strlen($type) - 5);510 $attr["type"] = "set";511 }512 else513 {514 if( $pos = strpos($type, " ") )515 $type = substr($type, 0, $pos);516 // parse field sizes517 if( $pos = strpos($type, "(") )518 {519 if( $pos1 = strpos($type, ",", $pos) )520 {521 $attr["size"] = (integer)substr($type, $pos + 1, $pos1 - $pos - 1);522 $attr["scale"] = (integer)substr($type, $pos1 + 1, strlen($type) - $pos1 - 2);523 }524 else525 {526 $attr["size"] = (integer)substr($type, $pos + 1, strlen($type) - $pos - 2);527 $attr["scale"] = 0;528 }529 $type = substr($type, 0, $pos);530 }531 $attr["type"] = $type;532 }533 if( !(strpos($field["Extra"], "auto_increment") === false) )534 $attr["auto_increment"] = "auto_increment";535 $attr["key"] = $field["Key"];536 $attr["default"] = $field["Default"];537 $attr["null"] = $field["Null"];538 539 echo '<field ';540 foreach($attr as $key => $value)541 {542 if( $value === null ) {543 $value = "";544 }545 echo $key.'="'.htmlspecialchars($value).'" ';546 }547 echo '/>';548 }549 echo "</fields>";550}551 552function showerror($conn)553{554 echo htmlspecialchars( db_error($conn) );555 exit();556}557 558function show_schema()559{560 global $conn;561 header("Content-type: text/xml");562 $phpversion = phpversion();563 // determine mysql version564 $mysqlversion = "unknown";565 $res = db_query("SHOW VARIABLES LIKE 'version'", $conn) or showerror($conn);566 if( $row = db_fetch_array($res) )567 $mysqlversion = $row["Value"];568 echo '<?xml version="1.0" standalone="yes" ?>';569?>570<phprunner phpversion="<?php echo htmlspecialchars($phpversion);?>" mysqlversion="<?php echo htmlspecialchars($mysqlversion);?>">571<tables>572<?php573 $tables = db_query("SHOW TABLES", $conn) or showerror($conn);574 if(!$tables)575 {576 echo db_error($conn);577 exit();578 }579 while( $table = db_fetch_numarray($tables) )580 {581?>582<table name="<?php echo htmlspecialchars( $table[0] );?>">583<?php584 showtablefields( $table[0] );585?>586</table>587 <?php588 }589?>590</tables>591</phprunner>592<?php593}594 595 596function connect5()597{598 $login = base64_decode( @$_REQUEST["login"] );599 $pwd = base64_decode( @$_REQUEST["pwd"] );600 $host = base64_decode( @$_REQUEST["host"] );601 602 $ssl = @$_REQUEST["ssl"];603 $port = @$_REQUEST["port"];604 $db = @base64_decode( @$_REQUEST["db"] );605 606 $conn = db_connect($host, $login, $pwd, $port, $ssl);607 608 if( $conn && strlen($db) )609 {610 if( !select_db($db, $conn) )611 {612 db_close($conn);613 return false;614 }615 db_query("set names utf8", $conn);616 }617 return $conn;618}619 620function testconnect5()621{622 echo "start-script-output";623 if( $conn = connect5() )624 {625 echo "ok";626 db_close($conn);627 }628 else629 echo db_error($conn);630 echo "end-script-output";631 exit();632}633 634function exec5()635{636 $query = base64_decode( @$_REQUEST["query"] );637 echo "start-script-output";638 if( !($conn = connect5()) )639 {640 echo db_error($conn);641 echo "end-script-output";642 exit();643 }644 if( db_query($query, $conn) )645 echo "ok";646 else647 echo db_error($conn);648 echo "end-script-output";649 650 db_close($conn);651 exit();652}653 654function query5()655{656 $query = base64_decode( @$_REQUEST["query"] );657 $reccount = @$_REQUEST["reccount"] + 0;658 $skip = @$_REQUEST["skip"] + 0;659 $blobsaschars = $_REQUEST["blobsaschars"];660 661 echo "start-script-output";662 if( !($conn = connect5()) || !($rs = db_query($query, $conn)) )663 {664 echo db_error($conn);665 echo "end-script-output";666 exit();667 }668 669 $bfields = array();670 echo "<output>";671 672 // display fields info673 echo "<fields>";674 for($i = 0; $i < getFieldsNumberInLastQuery($rs, $conn); $i++)675 {676 $finfo = getFieldInfo($rs, $i);677 $flags = strtolower( $finfo["flags"] );678 $type = $finfo["type"];679 $fieldName = $finfo["name"];680 681 if( $type == "blob" && ( strpos($flags, "binary") === false || $blobsaschars ) )682 $type = "text";683 684 echo "<field name=\"".xmlencode( $fieldName )."\" type=\"".xmlencode( $type )."\"";685 if( !$blobsaschars && strpos($flags, "binary") !== false && ( strpos($type, "char") !== false || strpos($type, "blob") !== false ) )686 {687 $bfields[] = true;688 echo ' binary="true"';689 }690 else691 $bfields[] = false;692 693 echo " />";694 }695 echo "</fields>";696 697 // display query data698 echo "<data>";699 $recno = 0;700 while( $data = db_fetch_numarray($rs) )701 {702 $recno++;703 if( $recno <= $skip )704 continue;705 if( $reccount >= 0 && $recno + $skip > $reccount)706 break;707 echo "<row>";708 foreach($data as $i => $val)709 {710 if( is_null($val) )711 echo '<field null="true" />';712 else if( $bfields[$i] )713 echo '<field>0x'.bin2hex($val).'</field>';714 else715 echo '<field>'.xmlencode($val).'</field>';716 }717 echo "</row>";718 }719 echo "</data>";720 echo "</output>";721 echo "end-script-output";722 723 db_close($conn);724 exit();725}726 727function xmlencode($str)728{729 $str = str_replace("&", "&", $str);730 $str = str_replace("<", "<", $str);731 $str = str_replace(">", ">", $str);732 $str = str_replace("\"", """, $str);733 return str_replace("'", "'", $str);734 735 /*736 $out = "";737 $len = strlen($str);738 $ind = 0;739 for($i = 0; $i < $len; $i++)740 {741 if( ord($str[$i]) >= 128 )742 {743 if( $ind < $i )744 $out.= substr($str, $ind, $i - $ind);745 $out.= "&#".ord($str[$i]).";";746 $ind = $i + 1;747 }748 }749 if( $ind < $len )750 $out.= substr($str, $ind);751 752 return str_replace("'", "'", $out);753 /**/754}755 756 757/**758 * Database connect wrapper759 * @param string host760 * @param string login761 * @param string password762 * @param string port763 * @return mixed A link identifier764 */765function db_connect($host, $login, $password, $port, $ssl)766{767 global $use_mysqli_ext;768 769 if( $use_mysqli_ext )770 {771 if($ssl)772 {773 if( !$port )774 $port = '3306';775 $conn = @mysqli_init();776 @mysqli_real_connect($conn, $host, $login, $password, "", $port, "", MYSQLI_CLIENT_SSL);777 return $conn;778 }779 780 $port = (integer)$port;781 if( $port )782 {783 return @mysqli_connect($host, $login, $password, "", $port);784 }785 786 return @mysqli_connect($host, $login, $password);787 }788 789 if( $port )790 $host = $host.":".$port;791 792 return @mysql_connect($host, $login, $password);793}794 795/**796 * Database select wrapper797 * @param string dbName A database name798 * @param mixed conn A link identifier799 * @return boolean800 */801function select_db($dbName, $conn)802{803 global $use_mysqli_ext;804 805 if( $use_mysqli_ext )806 return mysqli_select_db($conn, $dbName);807 808 return mysql_select_db($dbName, $conn);809}810 811/**812 * Get a list of databases813 * @param mixed conn A link identifier814 * @return mixed A result set identifier815 */816function get_dbs_list($conn)817{818 global $use_mysqli_ext;819 820 if( $use_mysqli_ext )821 return db_query("SHOW DATABASES", $conn);822 823 return @mysql_list_dbs($conn);824}825 826/**827 * Get a tables list for the database with a particular name828 * @param string dbName A database name829 * @param mixed conn A link identifier830 * @return mixed A result set identifier831 */832function get_tables_list($dbName, $conn)833{834 global $use_mysqli_ext;835 836 if( $use_mysqli_ext )837 return db_query("SHOW TABLES FROM ".$dbName, $conn);838 839 return mysql_list_tables($dbName, $conn);840}841 842/**843 * Database error wrapper844 * @param mixed conn A link identifier845 * @return string846 */847function db_error($conn)848{849 global $use_mysqli_ext;850 851 if( $use_mysqli_ext )852 {853 if($conn)854 return mysqli_error($conn);855 return mysqli_connect_error();856 }857 858 return mysql_error();859}860/**861 * Database fetch array wrapper862 * @param qhandle A result set identifier863 * @return array An array has numeric indices864 */865function db_fetch_numarray($qhandle)866{867 global $use_mysqli_ext;868 869 if( $use_mysqli_ext )870 return @mysqli_fetch_array($qhandle, MYSQLI_NUM);871 872 return @mysql_fetch_array($qhandle, MYSQL_NUM);873}874 875/**876 * Database fetch array wrapper877 * @param qhandle A result set identifier878 * @return array879 */880function db_fetch_array($qhandle)881{882 global $use_mysqli_ext;883 884 if( $use_mysqli_ext )885 return @mysqli_fetch_array($qhandle, MYSQLI_ASSOC);886 887 return @mysql_fetch_array($qhandle, MYSQL_ASSOC);888}889 890/**891 * Database close connection wrapper892 * @param mixed conn A link identifier893 * @return boolean894 */895function db_close($conn)896{897 global $use_mysqli_ext;898 899 if( $use_mysqli_ext )900 return mysqli_close($conn);901 902 return mysql_close($conn);903}904 905/**906 * Database query wrapper907 * @param string qstring908 * @param mixed conn A link identifier909 * @return mixed A result set identifier910 */911function db_query($qstring, $conn)912{913 global $use_mysqli_ext;914 915 if( $use_mysqli_ext )916 $ret = mysqli_query($conn, $qstring);917 else918 $ret = mysql_query($qstring, $conn);919 920 if( !$ret )921 trigger_error( db_error($conn), E_USER_ERROR );922 923 return $ret;924}925 926/**927 * Get the number of fields fetched by the last db-query928 * @return res A result set identifier929 * @param mixed conn A link identifier930 * @return number931 */932function getFieldsNumberInLastQuery($res, $conn)933{934 global $use_mysqli_ext;935 936 if( $use_mysqli_ext )937 return mysqli_field_count($conn);938 939 return mysql_num_fields($res);940}941?>