mysqli

PHP mysqli prepared statements removing leading zeros

大兔子大兔子 提交于 2020-01-03 03:40:17
问题 Im trying to enter a phone number into my database, the column is set as varchar(15) and inside phpmyadmin it will accept a phone number with a leading 0 (07712123123 for example). In my PHP script i have the variable $contactNo which is a string containing 07712123123 but when I use my prepared statement to input the data into the database the leading zero is removed. How can I stop this? // Insert data into customer_accounts if($stmt = $mysqli -> prepare("INSERT INTO customer_accounts

Variable amount of columns returned in mysqli prepared statement

有些话、适合烂在心里 提交于 2020-01-03 03:02:57
问题 I have a situation where a dynamic query is being generated that could select anywhere from 1 to over 300 different columns across multiple tables. It currently works fine just doing a query, however the issue I'm running into in using a prepared statement is that I do not know how to handle the fact that I don't know how many columns I will be asking for each time and therefor don't know how to process the results. The reason I believe a bind statement will help is because once this query is

Variable amount of columns returned in mysqli prepared statement

浪尽此生 提交于 2020-01-03 03:02:07
问题 I have a situation where a dynamic query is being generated that could select anywhere from 1 to over 300 different columns across multiple tables. It currently works fine just doing a query, however the issue I'm running into in using a prepared statement is that I do not know how to handle the fact that I don't know how many columns I will be asking for each time and therefor don't know how to process the results. The reason I believe a bind statement will help is because once this query is

Fetching rows from database via a prepared statement

随声附和 提交于 2020-01-03 02:49:08
问题 I initially created the below query to return some results from my database. $result = mysqli_query($con, "SELECT bookingId, locationName FROM bookings WHERE username = '$one'"); $output = array(); while($row = mysqli_fetch_assoc($result)) { $output[]=$row; } print(json_encode($output)); However, I now want to use prepared statements and have tried the below. But It always returns [] . Is this the correct way to return rows via a prepared statement. $stmt = $con->prepare('SELECT bookingId

MySQL: could not select data with time range

本秂侑毒 提交于 2020-01-03 02:48:12
问题 I wanted to select data, if date is matched and time is in between start time and end time. I have tried in many ways, but i am not succeed. check 3rd row in data table in below, start time 08:00:00 and end time is 11:00:00. it means 09:00:00 is between 08:00:00 and 11:00:00 Please help me. Here is my Query: SELECT * FROM (`rides`) WHERE `date` = '2013/04/30' AND `start_time` >= '9:00:00' AND `end_time` <= '9:00:00' Table structure if you need to know the datatype of field: CREATE TABLE IF

mysql_result() expects parameter 1 to be resource, object given

半腔热情 提交于 2020-01-03 02:27:10
问题 As a part of a login system I need to check if the username exists in the database so I created a query that checks if the username the user entered already exists. With mysql_result I check if the id is larger as null. If yes: user exists and if not the user doesn't exist. But here it goes wrong and wampserver gives me this error: Warning: mysql_result() expects parameter 1 to be resource, object given in users.php on line 6 function user_exists($username){ global $user_db; $username =

Passing mysqli to class for function use

南楼画角 提交于 2020-01-02 19:46:55
问题 Probably asked many times but I am hard-headed. I have the following class to manage a MySQL db. class blog { function show ($mysqli) { // Code working on $mysqli here } } Since I will be using $mysqli in many functions inside of this class I read that I can create constructors in order to pass the $mysqli variable to the class and use it inside of each function so I can do something like: $blog = new blog($mysqli); $blog -> show(); Is this possible? 回答1: This is called Dependency injection.

MySQLi wont establish connection within a pthreads worker

别等时光非礼了梦想. 提交于 2020-01-02 15:01:23
问题 Why cannot a mysqli connection be created when using a pthread worker in PHP? When establishing a mysqli and attempting to execute a query, will generatate an error PHP Warning: mysqli::query(): Couldn't fetch mysqli in W:\workspace\Sandbox\application.php on line 47 This is my script <?php // Application // Exceptions class MySQLWorkerException extends Exception {} class MySQLConnectionException extends Exception {} class MySQLQueryException extends Exception {} // Worker class SQLWorker

MySQL Selecting records by multiple IDs with LIMIT per each ID

夙愿已清 提交于 2020-01-02 10:07:09
问题 I'm stuck with my MySQLi query. The scenario is like this: - I need to select max 10 comments for each post. - I'm using this query but it doesn't work the way I need - Post IDs are in array $comments_query = mysqli_query($con, "SELECT * FROM comments WHERE pid IN ({$decodedPostIds}) AND state='1' order by time LIMIT 10"); LIMIT 10 applies for comments as whole. Thanks in advance for all advices and answers. Ps. I'm sorry for my english. Peter 回答1: LIMIT 10 says that the result will contain

Is validating $_GET id in database match secure enough?

孤者浪人 提交于 2020-01-02 07:30:10
问题 I have 2 pages on the website, one is index.php and index page list all posts that exist in database, and other page is post.php and post page display single post when clicked on specific post on index page. Now the code that i used to list all posts on index.php is: $postslist = mysqli_query($db, "SELECT * FROM posts"); while ($post = mysqli_fetch_array($postlist)) { echo '<a href="' .SITEURL.'/post.php?p='.$post['postid'].'>'.$post['title'].'</a>'; } And this works and i have all posts