function readData($ip_filter = "", $date_start_filter = "", $date_end_filter = "") { global $link; $sql_query = 'SELECT * FROM dataTable'; // Filter stuff // ... if ($ip_filter != "" || $date_start_filter != "" || $date_end_filter != "") { $sql_query = $sql_query . ' WHERE '; } if ($ip_filter != "") { $sql_query = $sql_query . ' IP="' . $ip_filter . '"'; if ($date_start_filter != "" || $date_end_filter != "") { $sql_query = $sql_query . ' AND'; } } if ($date_start_filter != "") { $sql_query = $sql_query . ' datetime>="' . $date_start_filter . '"'; if ($date_end_filter != "") { $sql_query = $sql_query . ' AND'; } } if ($date_end_filter != "") { $sql_query = $sql_query . ' datetime<="' . $date_end_filter . '"'; } $rows = array(); $result = mysqli_query($link, $sql_query); if (!$result) { echo 'An error occurred when querying the database:<p>'; print_r(mysqli_error_list($link)); echo '<p>Command: ' . $sql_query; die(''); } for ($idx = 0; $idx < mysqli_num_rows($result); $idx++) { array_push($rows, mysqli_fetch_array($result, MYSQL_NUM)); } return $rows; }
/** * *Envoie une requête à un serveur MySQL. * @param sql string * <p>Requete SQL.</p> * * * @return Pour les requêtes du type SELECT, SHOW, DESCRIBE, EXPLAIN et * les autres requêtes retournant un jeu de résultats, mysql_query() * retournera une ressource en cas de succès, ou FALSE en cas d'erreur. * * Pour les autres types de requêtes, INSERT, UPDATE, DELETE, DROP, etc., * mysql_query() retourne TRUE en cas de succès ou FALSE en cas d'erreur. */ function executeSQL($sql) { global $modeacces, $connexion, $logsql; //Formatage de la date pour le dichier log.txt $uneChaine = date("j M Y - G:i:s --> ") . $sql . "\r\n"; if ($logsql == "all") { ecritRequeteSQL($uneChaine); } else { if ($logsql == "modif") { $mot = strtolower(substr($sql, 0, 6)); if ($mot == "insert" || $mot == "update") { ecritRequeteSQL($uneChaine); } } } if ($modeacces == "mysql") { $result = mysql_query($sql) or die(afficheErreur($sql, mysql_error())); } if ($modeacces == "mysqli") { $result = $connexion->query($sql) or die(afficheErreur($sql, mysqli_error_list($connexion)[0]['error'])); //$mysqli->error_list; } return $result; }
public function getErrors() { return mysqli_error_list(self::$connection); }
//create vraibles named $user and $password, set them equal to whats stored in the POST array 'user' and 'password' elements. $user = $_POST['user']; $password = $_POST['password']; //create a variable called $loginQuery and use it to store an SQL query $loginQuery = " SELECT user, password\n FROM users\n WHERE user = '******' \n AND password = '******'"; //run the query using mysqli_query method, passing it the database connection and query as parameters.store the results in a variable $loginResult = mysqli_query($con, $loginQuery); //use mysqli_num_rows method to determine if $loginResult contains anything, if it does set $_SESSION array with user info and rediredct to list.php else redirect back to this page. if (mysqli_num_rows($loginResult) > 0) { echo "right"; $_SESSION['user'] = $user; $_SESSION['password'] = $password; header("Location:list.php"); die; } else { echo "wrong"; echo mysqli_error_list($con); echo mysqli_error($con); header('Location:loginIndex.php'); echo "Failed to login"; die; } } else { header("Location:loginIndex.php"); } } ?>
<?php /** * Created by PhpStorm. * User: apple * Date: 15/8/25 * Time: 下午5:40 */ require_once 'connDB.php'; $name = $_GET['name']; $query = "SELECT * FROM custominfo WHERE name LIKE '%{$name}%' OR aera LIKE '%{$name}%'"; $result = mysqli_query($db, $query) or die("传输数据失败" . mysqli_error_list($db) . mysqli_error($db) . mysqli_errno($db)); echo "<table>\n <thead>\n <tr>\n <td>客户名称</td>\n <td>客户电话</td>\n <td>客户所在区</td>\n <td>客户地址</td>\n </tr>\n </thead>\n <tbody>"; while ($row = mysqli_fetch_array($result)) { //var_dump($row[highprice].'yuan'); echo " <tr>\n <td class='name' id='editable'>{$row['name']}</td>\n <td class='type'>{$row['phone']}</td>\n <td class='midprice'>{$row['aera']}</td>\n <td class='highprice'>{$row['address']}</td>\n </tr>"; }
var_dump($variables); } echo "ok\n"; printf("\nMagic, magic properties:\n"); assert(mysqli_affected_rows($link) === $mysqli->affected_rows); printf("mysqli->affected_rows = '%s'/%s ('%s'/%s)\n", $mysqli->affected_rows, gettype($mysqli->affected_rows), mysqli_affected_rows($link), gettype(mysqli_affected_rows($link))); assert(mysqli_get_client_info() === $mysqli->client_info); printf("mysqli->client_info = '%s'/%s ('%s'/%s)\n", $mysqli->client_info, gettype($mysqli->client_info), mysqli_get_client_info(), gettype(mysqli_get_client_info())); assert(mysqli_get_client_version() === $mysqli->client_version); printf("mysqli->client_version = '%s'/%s ('%s'/%s)\n", $mysqli->client_version, gettype($mysqli->client_version), mysqli_get_client_version(), gettype(mysqli_get_client_version())); assert(mysqli_errno($link) === $mysqli->errno); printf("mysqli->errno = '%s'/%s ('%s'/%s)\n", $mysqli->errno, gettype($mysqli->errno), mysqli_errno($link), gettype(mysqli_errno($link))); assert(mysqli_error($link) === $mysqli->error); printf("mysqli->error = '%s'/%s ('%s'/%s)\n", $mysqli->error, gettype($mysqli->error), mysqli_error($link), gettype(mysqli_error($link))); if (version_compare(PHP_VERSION, '5.3.99', '>')) { assert(mysqli_error_list($link) === $mysqli->error_list); assert(is_array($mysqli->error_list)); } assert(mysqli_field_count($link) === $mysqli->field_count); printf("mysqli->field_count = '%s'/%s ('%s'/%s)\n", $mysqli->field_count, gettype($mysqli->field_count), mysqli_field_count($link), gettype(mysqli_field_count($link))); assert(mysqli_insert_id($link) === $mysqli->insert_id); printf("mysqli->insert_id = '%s'/%s ('%s'/%s)\n", $mysqli->insert_id, gettype($mysqli->insert_id), mysqli_insert_id($link), gettype(mysqli_insert_id($link))); assert(mysqli_sqlstate($link) === $mysqli->sqlstate); printf("mysqli->sqlstate = '%s'/%s ('%s'/%s)\n", $mysqli->sqlstate, gettype($mysqli->sqlstate), mysqli_sqlstate($link), gettype(mysqli_sqlstate($link))); assert(soundex(mysqli_stat($link)) == soundex($mysqli->stat)); printf("mysqli->stat = '%s'/%s ('%s'/%s)\n", $mysqli->stat, gettype($mysqli->stat), mysqli_stat($link), gettype(mysqli_stat($link))); assert(mysqli_get_host_info($link) === $mysqli->host_info); printf("mysqli->host_info = '%s'/%s ('%s'/%s)\n", $mysqli->host_info, gettype($mysqli->host_info), mysqli_get_host_info($link), gettype(mysqli_get_host_info($link))); /* note that the data types are different */ assert(mysqli_info($link) == $mysqli->info); printf("mysqli->info = '%s'/%s ('%s'/%s)\n", $mysqli->info, gettype($mysqli->info), mysqli_info($link), gettype(mysqli_info($link)));
<input type="submit" name="submit" id="submit" value=""/> <br/> <br/> <a href="index.html" style="text-decoration: none;color:white;font-size: 20px;margin-top: 20px;">回到首页</a> </form> </body> </html> <?php /** * Created by PhpStorm. * User: apple * Date: 15/7/6 * Time: 下午6:11 */ $name = $_POST['name']; $phone = $_POST['phone']; $area = $_POST['area']; $money = $_POST['money']; $date = $_POST['date']; require 'connDB.php'; //链接数据库的文件 //var_dump($name); for ($count = 0; $count < count($name); $count++) { $query = "INSERT INTO customnopay (name,phone,aera,howmuch,date) VALUES ('{$name[$count]}','{$phone[$count]}','{$area[$count]}','{$money[$count]}','{$date[$count]}')"; //echo $query; echo "<br />"; $result = mysqli_query($db, $query) or die("导入数据库失败" . mysqli_errno($db) . " " . mysqli_error_list($db) . ' ' . mysqli_error($db)); } mysqli_close($db);
function getSeasonYearTypes($db, $group_id) { //Use SQL Union to find seasons that belong to any group //$season_years = getSeasonYears(); //get all years //$season_types = getSeasonTypes(); //get all types $sql = "SELECT season_year, season_type, group_id FROM picks\n" . "UNION\n" . "SELECT season_year, season_type, group_id FROM g_seasons"; $result = mysqli_query($db, $sql) or die(mysqli_error_list($db)); while ($row = mysqli_fetch_array($result)) { $season_years[] = $row['season_year']; $season_types[] = $row['season_type']; $groups[] = $row['group_id']; } return [$groups, $season_years, $season_types]; }