mysqli

Handle decimal numbers in mysqli

ε祈祈猫儿з 提交于 2020-07-03 05:52:09
问题 I have to put the price of some items inside a mysql table. When creating the table I'm using DECIMAL(10,2) as I don't need more than 2 digits after the comma (for example: 123,45 would be accepted as an input but 123,456 would be rounded to 123,45 with PHP). First question: using DECIMAL(10,2) , how do I know how many numbers may be stored before the comma? I know it is not 10, as 10 is just the precision Mysql uses when doing math with those numbers: so where the length of the number itself

PHP MySQLi echo data in array without doing a while loop

蹲街弑〆低调 提交于 2020-07-03 04:05:11
问题 When using MySQLi , do I have to perform a kind of while loop where the actual data from the query is put into a variable array? $conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName); // Check if able to connect to database if ($conn->connect_error) { trigger_error("Database connection failed: " . $conn->connect_error, E_USER_ERROR); } $sql = "SELECT name FROM users WHERE email = '$email'"; $rs = $conn->query($sql); $numRows = $rs->num_rows(); I always do the following: $rs->data_seek(0);

PHP mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, object given [duplicate]

孤人 提交于 2020-06-29 17:56:21
问题 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 2 years ago . I am trying to get all my results from a database into and array: $sql = "SELECT * FROM posts WHERE user = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "i", $param_username_int); // Set parameters

Docker fails to install php mysql extension

天涯浪子 提交于 2020-06-28 04:26:11
问题 I'm just trying to get a simple docker dev environment setup, but docker is not installing php's mysql extension. I get a fatal error - Call to undefined function mysql_connect(). I've tried different php versions (5.4, 5.5, 5.6, 7.0) all with the same result. Any help would be appreciated. docker-compose.yml version: '2' volumes: database_data: driver: local services: nginx: image: nginx:latest ports: - 8080:80 volumes: - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf volumes

Closing prepared statements

£可爱£侵袭症+ 提交于 2020-06-26 05:06:09
问题 I know that closing prepared statements is a suggested thing to do. But I have a PHP script like this: $sql = "SELECT * FROM `mytable` WHERE ..."; $stmt = $dbh->stmt_init(); if($stmt->prepare($sql)) { $stmt->bind_param("s", $user); if($stmt->execute()) { $result = $stmt->get_result(); $stmt->close(); } else header("Location: .?error=unknown"); } else header("Location: .?error=conn"); The statement gets closed if everything is ok, but when something fails during the execution it doesn't get

How to make a fully dynamic prepared statement using mysqli API?

限于喜欢 提交于 2020-06-25 06:27:10
问题 I need to change this query to use a prepared statement. Is it possible? The query: $sql = "SELECT id, title, content, priority, date, delivery FROM tasks " . $op . " " . $title . " " . $content . " " . $priority . " " . $date . " " . $delivery . " ORDER BY " . $orderField . " " . $order . " " . $pagination . ""; Before the query, there's code to check the POST variables and change the content of variables in the query. //For $op makes an INNER JOIN with or without IN clause depending on the

mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it?

守給你的承諾、 提交于 2020-06-23 20:28:14
问题 In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error: Fatal error: Call to a member function bind_param() on a non-object in... Here is the code: global $mysqli; $stmt = $mysqli->prepare("SELECT id, description FROM tbl_page_answer_category WHERE cur_own_id = ?"); $stmt->bind_param('i', $cur_id); $stmt->execute(); $stmt->bind_result($uid, $desc); To check my query, I tried to execute the query via

PHP Form to delete records in mySQLi when displaying then in a table

你离开我真会死。 提交于 2020-06-23 16:48:51
问题 I'm making a system to display pages in the system in a table and one of the columns is the action column giving people the option to delete the page. I did this: listpages.php <?php $sql = "SELECT * FROM Pages"; $result = $conn->query($sql); if ($result) { while($row = $result->fetch_assoc()) { $pages[] = array_map('htmlspecialchars', $row); } } // PHP is finished now, here's the HTML ?> <form method="post" action="utils/delpage.php"> <table> <thead> <tr> <th>Page Name</th> <th>Page Type</th

How to dynamically bind params in mysqli prepared statement?

≡放荡痞女 提交于 2020-06-22 12:47:10
问题 I'm trying to create a function for my project. I would like it to handle all the check functions. What I mean with that is before you start inserting a row in your database you check if a row exists with that email address. To use this function dynamically it needs to be flexible. So I did put my variables in an array, but mysqli_stmt_bind_param can't handle arrays. As a solution, I tried making a foreach loop. The query: $sql = "SELECT users_id, users_email FROM users WHERE users_id = ? AND

warning :: invalid object or resource mysqli_stmt. What is the meaning and solution(s)?

霸气de小男生 提交于 2020-06-21 05:08:07
问题 The following code is throwing the mysterious Warnings. I can't understand what they mean. What do these errors indicate and how to eradicate them? require "conn.php"; $q = mysqli_stmt_init($dbconn); $query = "SELECT users.userid FROM users WHERE users.email = ? "; mysqli_stmt_prepare($q, $query); mysqli_stmt_bind_param($q, "s", $email); mysqli_stmt_execute($q); $result = mysqli_stmt_get_result($q); if (mysqli_num_rows($result) == 0) { $q = mysqli_stmt_init($dbconn); $query = "INSERT INTO