mysqli

SQL LIKE query failing - fatal error in prepared statement

末鹿安然 提交于 2019-12-30 13:13:26
问题 I have the following code: $countQuery = "SELECT ARTICLE_NO FROM ? WHERE upper(ARTICLE_NAME) LIKE '% ? %'"; if ($numRecords = $con->prepare($countQuery)) { $numRecords->bind_param("ss", $table, $brand); $numRecords->execute(); $data = $con->query($countQuery) or die(print_r($con->error)); $rowcount = mysql_num_rows($data); $rows = getRowsByArticleSearch($query, $table, $max); $last = ceil($rowcount/$page_rows); } Which should work fine. However I receive the error that : You have an error in

SQL LIKE query failing - fatal error in prepared statement

匆匆过客 提交于 2019-12-30 13:12:42
问题 I have the following code: $countQuery = "SELECT ARTICLE_NO FROM ? WHERE upper(ARTICLE_NAME) LIKE '% ? %'"; if ($numRecords = $con->prepare($countQuery)) { $numRecords->bind_param("ss", $table, $brand); $numRecords->execute(); $data = $con->query($countQuery) or die(print_r($con->error)); $rowcount = mysql_num_rows($data); $rows = getRowsByArticleSearch($query, $table, $max); $last = ceil($rowcount/$page_rows); } Which should work fine. However I receive the error that : You have an error in

php mysqli check if mysqli query returns false

若如初见. 提交于 2019-12-30 12:15:45
问题 How can I check mysqli query if it returns boolean(false) or the result? If I try getting the num_rows I get php error because I'm trying to access a non object as object. But I need to check this because if its false I have to set a variable and if its not than get the result of the query. my query looks like this: <?php $q = "SELECT `id` FROM `table` ORDER BY `id` DESC LIMIT 0, 1"; $res = mysqli->query($q); ?> 回答1: You need to use === operator which also checks arguments type: $q = "select

Mysqli Prepared Stmt returns 0 num_rows

↘锁芯ラ 提交于 2019-12-30 11:32:12
问题 Help. I am getting 0 num_rows but if i execute the query in the console i am getting results. I m kinda new to prepared stmts. Here is my code Database connection class: class DbConnection { const HOST = "localhost"; const USR = "root"; const PWD = ""; const DB = "club_db"; } Login class: class UsrLogin extends DbConnection { private $conn; /*db connector*/ /*login vars*/ private $usr; private $pwd; /*ctrl var*/ public $AccessGranted = false; function __construct($username,$password){ /

php MySqli : How can i rewrite fetch to fetch_assoc? LIKE CONCAT

家住魔仙堡 提交于 2019-12-30 11:11:16
问题 Helo, I using "bind_result", "LIKE CONCAT" ... to reach full text search and pagination by two query string. but how can I change bind_result methods to fetch_assoc? <?php $mysqli = new mysqli("localhost", "", "", "test"); $query_string="hello"; //keywords $sqltxt="SELECT * FROM `table` WHERE text1 LIKE CONCAT('%', ?, '%')"; //first query : for get the total number of data $stmt = $mysqli->prepare($sqltxt); $stmt->bind_param("s",$query_string); $stmt->execute(); $stmt->store_result(); $total

Error while reading greeting packet

一曲冷凌霜 提交于 2019-12-30 10:03:47
问题 i have problem ... im tring to connect to server in netbeans .... I write the code as bellow: <?php echo "wlecome"; echo "<br>"; $conn=mysqli_connect("mydomain.com:2082", "phpmyadmin_user", "password","database_name"); echo $conn; ?> runing of this code return this erreurs: wlecome Warning: mysqli_connect(): MySQL server has gone away in C:\xampp\htdocs\myprojet\index.php on line 10 Warning: mysqli_connect(): Error while reading greeting packet. PID=1092 in C:\xampp\htdocs\myprojet\index.php

My sql query to get middle row values using GROUP BY function

Deadly 提交于 2019-12-30 09:50:12
问题 My database structure is like Id Price Code 1 0.12 93 2 0.13 93 3 0.54 93 4 0.96 93 5 0.10 94 6 0.30 94 7 0.90 94 8 1.40 94 9 2.30 94 I have to fetch the data using group by code and i want the middle row as output. In the above example i want the output as Id Price Code 3 0.54 93 7 0.90 94 The above is the output that i want with the middle row or the row having maximum price value in case of two middle rows like in case of row count 4,6,8 回答1: SELECT table1.* FROM table1 JOIN ( SELECT

How to load MySQLi result set into two-dimensional array?

拜拜、爱过 提交于 2019-12-30 09:36:15
问题 I've got a problem with the mysqli result set. I have a table that contains a bunch of messages. Every table row represents one message. I have a few columns like ID, title, body, and 'public'. The public column contains booleans, that specify if the message is to be displayed to everyone, or just to the person who posted it. I have a page where I want to display all public messages, and if you click on a message, you get a page with the single message, and some extra options. To do this, I

“Load data local infile” command not allowed

試著忘記壹切 提交于 2019-12-30 09:09:20
问题 I am using the PHP mysqli library. Every time I try to run a LOAD DATA LOCAL INFILE command, mysqli complains with the message The used command is not allowed with this MySQL version I do not have the same problem with running the command from a MySQL terminal (must login with --local-infile=1 to make it work) or PHPMyAdmin. Just my PHP+mysqli code experiences this error. I tried setting this option: mysqli_options($cnx, MYSQLI_OPT_LOCAL_INFILE, 1); prior to my load data call, but still no

prepared statement method.. confused

匆匆过客 提交于 2019-12-30 07:50:13
问题 I don't know what's missing or why it isn't displaying data. My code is working if I'm not using prepared statements. When I used prepared statements, it seems that code is not working anymore. db.php Class Database{ public $mysqli; public function __construct($db_host, $db_user, $db_password, $db_name){ $this->con = new mysqli($db_host, $db_user, $db_password, $db_name); } public function selectUserInfo($id){ $stmt = $this->con->prepare("SELECT * FROM users WHERE os_id = ?"); $stmt->bind