mysqli

why does mysqli fetch create an infinite loop when in function?

寵の児 提交于 2020-01-05 07:29:28
问题 Why does this function return an infinite loop? I am trying to create a function where you just have to give it the query and the while loop takes care of the rest. but for some reason ONLY when i have the function return $q->fetch_assoc() it goes into an infinite loop. if I return just $q, then call $q->fetch_assoc() in the while loop then it doesn't cause the infinite loop. public function fetch($query){ $con = $this->con; $q = $con->query($query); return $q->fetch_assoc(); } while($r =

Left Join Table and Echo in Table - MySQLi Query

谁都会走 提交于 2020-01-05 07:20:30
问题 I am new in PHP and MYSQL database. I am trying to display row in table from my two table. I want all row from table called teacher_profile and want name column from center. I am able to run query in phpmyadmin and its working fine but issue is both table have name is common so I am not able to properly display centername in my table. because there teacher_profile and center both have name column. I can not rename it because its live and used with my android application. select * from teacher

Mysqli insert id: $mysqli->insert_id; or $ID_user=$stmt->insert_id?

旧巷老猫 提交于 2020-01-05 05:52:26
问题 which one is the correct code in a prepared statement? $ID_user=$mysqli->insert_id; or $ID_user=$stmt->insert_id; ? $stmt = $mysqli->prepare("INSERT INTO users (first_name, last_name) VALUES (? ,?)"); $stmt->bind_param("ss",$first_name,$last_name); if($stmt->execute()) { $ID_user=$mysqli->insert_id; // or $ID_user=$stmt->insert_id; } 回答1: There is absolutely no difference, you can use whatever you wish. 来源: https://stackoverflow.com/questions/43184732/mysqli-insert-id-mysqli-insert-id-or-id

Mysqli insert id: $mysqli->insert_id; or $ID_user=$stmt->insert_id?

社会主义新天地 提交于 2020-01-05 05:52:08
问题 which one is the correct code in a prepared statement? $ID_user=$mysqli->insert_id; or $ID_user=$stmt->insert_id; ? $stmt = $mysqli->prepare("INSERT INTO users (first_name, last_name) VALUES (? ,?)"); $stmt->bind_param("ss",$first_name,$last_name); if($stmt->execute()) { $ID_user=$mysqli->insert_id; // or $ID_user=$stmt->insert_id; } 回答1: There is absolutely no difference, you can use whatever you wish. 来源: https://stackoverflow.com/questions/43184732/mysqli-insert-id-mysqli-insert-id-or-id

When to use prepared statements?

我们两清 提交于 2020-01-05 05:50:11
问题 I have few question. Spec: MySql database; server side language PHP 5.3.10 1) When should one use prepared statements? I am building a webapp which has users. I am retrieving/inserting data into the database constantly. I am currently not using prepared statements and I was wondering if that was wrong way of doing things? /** * Register a new user into the database. Please make sure to * hash the password. * @param type $fName First name of the user - String value. * @param type $lName Last

Detecting relationships among MySQL DB records

自古美人都是妖i 提交于 2020-01-05 04:19:24
问题 Let's say I have 3 DB tables: teachers, with the following fields: id name subjects, with the following fields: id name teachers-subjects, with the following fields: teacher_id subject_id So, a relationship comes some teachers have subjects in common. I've thought about the algorithm for querying: For each record s in subjects table: Select the count in teachers_subjects table. If count is greater than 1 In teacher_subjects, get teacher_id's where subject_id is s. Make the relationship pairs.

bind_result( ) not getting all results

霸气de小男生 提交于 2020-01-05 04:15:26
问题 For some reason it executes the statement and then the bind_results returns all values but not the last value of $postContent. <?php if (isset($_GET['postID'])) { $postID = $_GET['postID']; $stmt = $mysqli->prepare("SELECT * FROM Posts WHERE postID = ?"); $stmt->bind_param('i', $postID); $stmt->execute(); $stmt->bind_result($postID, $postTitle, $postCat, $postUser, $postDateTime, $postContent); $stmt->fetch(); echo $postContent; ?> <h1><?php echo $postTitle;?></h1> </div> <!-- End of box div

mysqli_stmt::execute() returning false and statement not executing

前提是你 提交于 2020-01-04 12:40:28
问题 I have a simple login system protection mechanism by recording the user's IP, failed attempt number and last attempt time to a MySQL database table named bannedusers . However when I attempt to use the following code below to insert a new entry into the database the execute() function returns false and fails to execute. Code as follows: private $con; function updateTable($IP, $attempt, $exists){ $time = time(); //The following statement is actually in the constructor, moved here for

How to dynamically generate SQL query based on user's selections?

北慕城南 提交于 2020-01-04 09:30:35
问题 I need to create a GUI, using which users can select several attributes which will be used to query the database to find suitable persons. I'm looking for ideas how to dynamically generate the database query according to user's choices. Query will contain several fields, but to get the idea I will include only three of those below as an example: Occupation - there can be 0 to n occupation strings. If occupation strings are given, one of them have to match. Age - age can be given as: exact

Errors In PHP code

南楼画角 提交于 2020-01-04 09:25:40
问题 I am doing PHP coding for first time. I got the following errors: Errors : Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\331002.php on line 9 Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\331002.php on line 10 Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\331002.php on line 11 Notice: Undefined index: empID in C:\xampp