Created
July 10, 2016 14:40
-
-
Save anonymous/3a1ad6a6efe8edaf7f5a531784b82464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function query_sql( $srv, $qry ) { | |
// 1 - Tratar o endereço do servidor | |
if( empty ( $srv ) ) { | |
echo "Especifique servidor, usuário e senha <br>"; | |
$srv = "0"; } | |
else { | |
$srv_arr = explode( " ", $srv, 3 ); | |
$hst = $srv_arr [0]; | |
$usr = $srv_arr [1]; | |
$snh = $srv_arr [2]; | |
echo "Testando \$hst, \$usr, \$snh: ". | |
$hst." ".$usr." ".$snh." <br><br>"; | |
$lnk = mysqli_connect ( $hst, $usr, $snh ); | |
if( !$lnk ) { die( 'Conexão inválida: <br><br>'. | |
mysql_connect_error() ); }; | |
echo "Conexão conectada com sucesso! <br><br>"; | |
if( empty( $qry ) ) { echo "Query vazia!<br><br>"; } | |
else { | |
$res = mysql_query( $qry ); | |
if( empty( $res ) ) { | |
echo "Testando \$res: vazia! <br><br>"; } | |
else { echo "Testando \$res: ".$res." <br><br>"; } | |
if( !$res ) { | |
die( 'Query inválida! - mysql_error(): '. | |
mysql_error() ); } else { return $res; } | |
} // else empty( $qry )? | |
} // else empty( $srv )? | |
} // query_sql( $srv, $qry ) | |
$usr = "lucasribeiro"; | |
query_sql( // Testando: query_sql(); | |
"localhost root mysql.3j286", | |
"USE FERRAMENTAS; SELECT * FROM ". | |
"Login WHERE usuario=$usr" ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment