mysqli

PHP MySQLi is just returning one row in JSON

旧城冷巷雨未停 提交于 2020-04-07 05:11:10
问题 I am working on the below code. Why am I getting only one row in my JSON output? $items = []; if ($stmt = $this->conn->prepare("SELECT * FROM $tbl")) { $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $items = $row; } $stmt->free_result(); $stmt->close(); } $this->conn->close(); } echo json_encode($items); 回答1: This happens because you are going through the rows and assigning each of them to $items : while ($row = $result-

Why doesn't it want to register me

余生长醉 提交于 2020-03-25 19:21:08
问题 for a school assingment i have to make a portfolio. this has to contain a working login and registration system. I got it where it will log people in but only if i manually input data in a database. but now when i try to let people register them self it just keeps giving me the error that the username and email allready exists, what is not true in most cases. i hope u guys can help me with this. here is the code: <?php include_once 'db_connect.php'; include_once 'psl-config.php'; $error_msg =

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given [duplicate]

混江龙づ霸主 提交于 2020-03-23 06:19:06
问题 This question already has an answer here : mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it? (1 answer) Closed 4 hours ago . Why am I getting this error message: Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given My code is: $statement = "INSERT INTO table1 (data1, data2) VALUES ('$variable1', '$variable2')"; if ($result = mysqli_query($conn,$statement)) { echo "New record

I need to convert all the PDO in my function to MYSQLI but can't find the PDO alternatives

丶灬走出姿态 提交于 2020-03-20 12:36:56
问题 I am trying to find a way to convet my PDO::PARAM_INT and the other pdo values in the switch statement below to use mysqli. I am doing a portfolio project and for school and found out we are not allowed to use PDO for some reason so now I have to restructure 10 pages. Thanks in advance! public function bind($param, $value, $type = null){ if(is_null($type)){ switch(true){ case is_int($value): $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; case is_null(

I need to convert all the PDO in my function to MYSQLI but can't find the PDO alternatives

元气小坏坏 提交于 2020-03-20 12:36:30
问题 I am trying to find a way to convet my PDO::PARAM_INT and the other pdo values in the switch statement below to use mysqli. I am doing a portfolio project and for school and found out we are not allowed to use PDO for some reason so now I have to restructure 10 pages. Thanks in advance! public function bind($param, $value, $type = null){ if(is_null($type)){ switch(true){ case is_int($value): $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; case is_null(

mysqli::real_connect(): (HY000/1049): Unknown database error in codeigniter

不羁的心 提交于 2020-03-14 05:17:46
问题 I'm new to Codeigniter PHP framework. When I'm testing my application I get 'Unknown database db_name' error. I have browsed through several sites but didn't found solution for the problem as I'm trying the same to connect with wamp's mysql database. Any help would be appreciable. Following is database.php in config folder: image describing Test database: $active_group = 'default'; $query_builder = TRUE; $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root',

mysqli::real_connect(): (HY000/1049): Unknown database error in codeigniter

橙三吉。 提交于 2020-03-14 05:16:00
问题 I'm new to Codeigniter PHP framework. When I'm testing my application I get 'Unknown database db_name' error. I have browsed through several sites but didn't found solution for the problem as I'm trying the same to connect with wamp's mysql database. Any help would be appreciable. Following is database.php in config folder: image describing Test database: $active_group = 'default'; $query_builder = TRUE; $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root',

解析Dockerfile

妖精的绣舞 提交于 2020-03-09 09:33:48
Dockerfile就是一个描述镜像具体组成的具体文件,可以根据这个文件构建镜像。 FROM:指定基础镜像 FROM centos:7 MAINTAINER:镜像维护信息 MAINTAINER Benjamin Yang <133xxxx2282@163.com> RUN:执行命令 RUN ["yum", "install", "httpd"] RUN yum install httpd COPY:复制文本 COPY <源路径>... <目标路径> COPY ["<源路径1>",... "<目标路径>"] <源路径> 可以是多个、以及使用通配符,通配符规则满足Go的filepath.Match 规则,如:COPY *.txt /workdir/ COPY hom?.txt /mydir/ <目标路径>使用 COPY 指令,源文件的各种元数据都会保留。比如读、写、执行权限、文件变更时间等。 ADD:高级复制文件 ADD jdk-8u45-linux-x64.tar.gz / <源路径> 可以是一个 URL ,下载后的文件权限自动设置为 600 。 CMD:容器启动命令 shell 格式: CMD <命令> exec 格式: CMD ["可执行文件", "参数1", "参数2"...] CMD nginx -g "daemon off;" CMD ["nginx", "-g",

Set $mysqli as a global variable for OOP

╄→尐↘猪︶ㄣ 提交于 2020-03-03 07:35:27
问题 Ok, This is sort of an involved problem, but any help or advice would be incredibly appreciated. So I'm working with a site that (using .htaccess ) redirects all traffic to a load.php . For any sql functionality, I have an abstract class that has a lot of query statements as functions that pass parameters to define the specifics of each query. e.g. $table->update("constraints") I'm trying to figure out how to set the connection to the database on load.php , and then set the connection as a

PHP MySQLi fetch “array push” overrides data

≯℡__Kan透↙ 提交于 2020-03-01 18:36:14
问题 I have 2 arrays: $arr = []; $tempArray = [ 'val1' => "xxx", 'val2' => 0, 'val3' => 0 ]; Then in my mysql query i fill the temp array with values from the current row and finally push him into the $arr: $stmt->bind_result($tempArray["val1"], $tempArray["val2"], $tempArray["val3"]); while ( $stmt->fetch () ) { array_push($arr, $tempArray); } The Problem is, on every loop the "array_push" overrides the data in the $arr . For example I loop 3 times in the $stmt->fetch() . 1. Loop $tempArray = [