本文整理匯總了PHP中mysqli_fetch_assoc函數的典型用法代碼示例。如果您正苦於以下問題:PHP mysqli_fetch_assoc函數的具體用法?PHP mysqli_fetch_assoc怎麽用?PHP mysqli_fetch_assoc使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mysqli_fetch_assoc函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: check_user
function check_user($uid, $link)
{
$query = "SELECT sid FROM " . USERS_TABLE . " WHERE uid='{$uid}';";
$result = mysqli_query($link, $query) or die(mysqli_error());
$row = mysqli_fetch_assoc($result);
return $row["sid"] == SID ? true : false;
}
示例2: deleteInstitution
function deleteInstitution($institutionId)
{
//Delete all children of Institution
$conn = connectToDatabase();
mysqli_begin_transaction($conn, MYSQLI_TRANS_START_READ_WRITE);
$sql = "SELECT CURP FROM BelongsToInstitution WHERE institutionId = '{$institutionId}';";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
deleteChildSameConnection($row["CURP"], $conn);
}
}
//Delete all users from institution
$sql = "SELECT userName FROM WorksInInstitution WHERE institutionId = '{$institutionId}';";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
deleteUserSameConnection($row["userName"], $conn);
}
}
$sql = "DELETE FROM Institution WHERE institutionId = '{$institutionId}'";
if (mysqli_query($conn, $sql)) {
echo "1";
} else {
echo "0" . mysqli_error($conn);
}
mysqli_commit($conn);
closeDb($conn);
}
示例3: view
public function view()
{
$sql = "SELECT * FROM herramientas WHERE idHerramienta = '{$this->idHerramienta}'";
$datos = $this->con->consultaRetorno($sql);
$row = mysqli_fetch_assoc($datos);
return $row;
}
示例4: validateUser
function validateUser($user, $pass, $pass_confirm)
{
$valueToRetun = 0;
$validUsernameOrNot = validUsername($user);
$validPasswordOrNot = validPassword($pass);
//check to see if username exists
$sqlQuery = "SELECT * FROM users WHERE username = '{$user}'";
$result = mysqli_query($connection, $sqlQuery);
$row = mysqli_fetch_assoc($result);
if ($row != "") {
$valueToReturn = 1;
} else {
if ($validUsernameOrNot && $validPasswordOrNot) {
$valueToReturn = 2;
//Username and password is valid
} else {
if (!$validUsernameOrNot) {
$valueToReturn = 3;
//Username is not valid format
} else {
if (!$validPasswordOrNot) {
$valueToReturn = 4;
//Password is not valid format
} else {
if (strcmp($pass, $pass_confirm) !== 0) {
$valueToReturn = 5;
//Password confirmation is incorrect
}
}
}
}
}
mysql_free_result($result);
return $valueToReturn;
}
示例5: view
public function view()
{
$sql = "SELECT t1.*, \n t2.nombre as nombre_seccion\n FROM estudiantes t1 \n INNER JOIN secciones t2 \n ON t1.id_seccion = t2.id\n WHERE t1.id = '{$this->id}'";
$datos = $this->con->consultaRetorno($sql);
$row = mysqli_fetch_assoc($datos);
return $row;
}
示例6: post_query
function post_query($col)
{
include 'conn.php';
// Get the number of row of a table
$sql = "SELECT count(id) FROM blog";
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_row($query);
// Catch the session variable from another page
$n = $_SESSION['var'];
for ($i = 1; $i <= $row[0]; $i++) {
$sql = "SELECT * FROM blog where id = {$n} order by time asc";
// For query
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($query);
if ($col == 'post_detail') {
str_cut($row['post_detail']);
break;
} elseif ($col == 'author') {
echo $row['author'];
break;
} elseif ($col == 'time') {
echo $row['time'];
break;
} elseif ($col == 'post_heading') {
echo $row['post_heading'];
break;
} elseif ($col == 'image') {
echo $row['image'];
break;
} elseif ($col == 'id') {
echo $row['id'];
break;
}
}
}
示例7: validaUsuario
/**
* Função que valida um usuário e senha
*
* @param string $usuario - O usuário a ser validado
* @param string $senha - A senha a ser validada
*
* @return bool - Se o usuário foi validado ou não (true/false)
*/
function validaUsuario($usuario, $senha)
{
global $_SG;
$cS = $_SG['caseSensitive'] ? 'BINARY' : '';
// Usa a função addslashes para escapar as aspas
$nusuario = addslashes($usuario);
$nsenha = addslashes($senha);
// Monta uma consulta SQL (query) para procurar um usuário
$sql = "SELECT `id`, `nome` FROM `" . $_SG['tabela'] . "` WHERE " . $cS . " `usuario` = '" . $nusuario . "' AND " . $cS . " `senha` = '" . $nsenha . "' LIMIT 1";
$query = mysqli_query($sql);
$resultado = mysqli_fetch_assoc($query);
// Verifica se encontrou algum registro
if (empty($resultado)) {
// Nenhum registro foi encontrado => o usuário é inválido
return false;
} else {
// Definimos dois valores na sessão com os dados do usuário
$_SESSION['usuarioID'] = $resultado['id'];
// Pega o valor da coluna 'id do registro encontrado no MySQL
$_SESSION['usuarioNome'] = $resultado['nome'];
// Pega o valor da coluna 'nome' do registro encontrado no MySQL
// Verifica a opção se sempre validar o login
if ($_SG['validaSempre'] == true) {
// Definimos dois valores na sessão com os dados do login
$_SESSION['usuarioLogin'] = $usuario;
$_SESSION['usuarioSenha'] = $senha;
}
return true;
}
}
示例8: createOpenInvoiceList
function createOpenInvoiceList()
{
$currentDate = date('Ymd');
$res = mysqli_query_check("select count(*) as cnt from {prefix}invoice i where i.deleted = 0 AND i.interval_type > 0 AND i.next_interval_date <= {$currentDate} AND i.archived = 0");
$row = mysqli_fetch_assoc($res);
if ($row['cnt'] > 0) {
createList('open_invoices', 'invoice', 'resultlist_repeating_invoices', $GLOBALS['locLabelInvoicesWithIntervalDue'], "i.interval_type > 0 AND i.next_interval_date <= {$currentDate} AND i.archived = 0", true);
}
$open = '';
$res = mysqli_query_check('SELECT id FROM {prefix}invoice_state WHERE invoice_open=1');
while ($id = mysqli_fetch_value($res)) {
if ($open) {
$open .= ', ';
}
$open .= $id;
}
$unpaid = '';
$res = mysqli_query_check('SELECT id FROM {prefix}invoice_state WHERE invoice_unpaid=1');
while ($id = mysqli_fetch_value($res)) {
if ($unpaid) {
$unpaid .= ', ';
}
$unpaid .= $id;
}
if ($open) {
createList('open_invoices', 'invoice', 'resultlist_open_invoices', $GLOBALS['locLabelOpenInvoices'], "i.state_id IN ({$open}) AND i.archived=0", true);
}
if ($unpaid) {
createList('open_invoices', 'invoice', 'resultlist_unpaid_invoices', $GLOBALS['locLabelUnpaidInvoices'], "i.state_id IN ({$unpaid}) AND i.archived=0", true, true);
}
}
示例9: verificar_login
function verificar_login($userid, $pass, &$result)
{
$servername = "localhost";
$username = 'root';
$password = "";
$dbname = "cmd";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `trabajador` WHERE `userid`=\"" . $userid . "\" and `password`=\"" . $pass . "\"";
$result = mysqli_query($conn, $sql);
$count = 0;
if (!$result) {
echo "no result";
} else {
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$_SESSION['userid'] = $row["userid"];
$_SESSION['rol'] = $row["rol"];
$count++;
}
}
if ($count == 1) {
return 1;
} else {
return 0;
}
}
}
示例10: fetch_record
function fetch_record($query)
{
global $connection;
$result = $connection->query($query);
return mysqli_fetch_assoc($result);
//return $result->fetch_assoc();
}
示例11: queryToArray
public static function queryToArray($sql)
{
global $my_user, $my_pass, $my_host, $my_db, $config_enable_cache;
$link = Database::getLink();
$db_selected = mysqli_select_db($link, $my_db);
if (!$db_selected) {
die('Can\'t use ' . $my_db . ' : ' . mysqli_error($link));
}
// Perform Query
$result = mysqli_query($link, $sql);
$id = mysqli_insert_id($link);
if ($id > 0) {
// we did an insert, just return the id
return $id;
}
//echo ("\ndatabase qtoa before proc id is $id");
if (!$result) {
$message = 'Invalid query: ' . mysqli_error($link) . "\n";
$message .= 'Whole query: ' . $sql;
die($message);
}
if ($result === true) {
// probably an insert..
return false;
}
$rows = array();
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
示例12: getRank
function getRank($a, $b, $c)
{
include 'config.php';
$con = mysqli_connect($IP, $user, $pass, $db);
// echo "select `idCategory` from Placed where `idBid`=$c and `idAuction`=$a";
// echo "select `idCategory` from Placed where `idBid`=$c and `idAuction`=$a";
//echo "select `idCategory` from Placed where `idBid`=$c and `idAuction`=$a";
// $result=mysqli_query($con,"select `idCategory` from Placed where `idBid`=$c and `idAuction`=$a") or die(mysqli_error($con));
$result = mysqli_query($con, "select `idCategory` from Placed where `idBid`={$c} and `idAuction`={$a}") or die(mysqli_error($con));
// echo "select count(*)+1 as rank from Placed where `Price`>$b and `idAuction`=$a and `status` = 'A'";
// echo json_encode($result);
// echo mysqli_num_rows($result);
$row = mysqli_fetch_assoc($result);
$c = $row['idCategory'];
// echo $c.'sdf';
if (empty($c)) {
return 0;
}
// echo "select count(*)+1 as rank from Placed where `Price`>$b and `idCategory`=$c and `idAuction`=$a and `status` = 'A'";
//echo "select count(*)+1 as rank from Placed where `Price`>$b and `idCategory`=$c and `idAuction`=$a and `status` = 'A'";
$result = mysqli_query($con, "select count(*)+1 as rank from Placed where `Price`>{$b} and `idCategory`={$c} and `idAuction`={$a} and `status` = 'A'") or die("Error" . mysqli_error($con));
$output = [];
while ($row = mysqli_fetch_assoc($result)) {
return $row['rank'];
}
}
示例13: query
function query($SQL, $select = false)
{
static $CONFIG = ['server' => 'localhost', 'username' => 'root', 'password' => 'root', 'database' => 'wt'];
static $connection;
if (!isset($connection)) {
// Create connection
$connection = mysqli_connect($CONFIG['server'], $CONFIG['username'], $CONFIG['password'], $CONFIG['database']);
if (!$connection) {
die('Could not connect to database!');
}
}
if ($select) {
// IS A SELECT QUERY, RETURN ARRAY
$results = mysqli_query($connection, $SQL);
$toReturn = [];
if (mysqli_num_rows($results) > 0) {
while ($result = mysqli_fetch_assoc($results)) {
array_push($toReturn, $result);
}
}
return $toReturn;
} else {
// RETURN BOOL
if (mysqli_query($connection, $SQL)) {
return true;
} else {
return false;
}
}
// Execute SQL
}
示例14: preffAction
public function preffAction(Request $request)
{
$Applicant_id = $request->get('id');
$result = get_all_schools();
$schools = array();
while ($row = mysqli_fetch_assoc($result)) {
array_push($schools, $row);
}
$postData = $request->request->all();
if (isset($postData['submit']) && isset($postData['school'])) {
$count = 0;
foreach ($postData['school'] as $school) {
if (isset($school['sid']) && $school['id'] != "") {
$connection = connect();
$no = $school['id'];
$sch_id = $school['sid'];
$query = "insert into applicant_has_school (";
$query .= " Applicant_id, school_id, preferrence_no";
$query .= ") values( ";
$query .= " '{$Applicant_id}','{$sch_id}','{$no}'";
$query .= ")";
$result = mysqli_query($connection, $query);
colse_connection($connection);
}
$count++;
}
return $this->redirectToRoute('childrenofstaff_new', array('id' => $Applicant_id));
}
return $this->render('applicant/preferrence.html.twig', array('schools' => $schools, 'id' => $Applicant_id));
}
示例15: Populate
function Populate()
{
//mysql connection
$con = mysqli_connect("eu-cdbr-azure-west-a.cloudapp.net", "b8592f1b44ff9a", "fecb2128", "TeamProject");
if (mysqli_connect_errno()) {
$result = "f";
} else {
//query
$query = "SELECT Name,Email FROM Subscriber";
$result = mysqli_query($con, $query);
//initialize arrays
$i = 0;
$subnames = array();
$submails = array();
//loop through the database populating
while ($sub = mysqli_fetch_assoc($result)) {
$subnames[$i] = $sub['Name'];
$submails[$i] = $sub['Email'];
$i++;
}
//close conection and return
mysqli_close($con);
return array($subnames, $submails);
}
}