mysqli

msqli does not INSERT

走远了吗. 提交于 2020-01-06 01:09:29
问题 im trying to insert data from a form (via POST) into a MySQL database, it does not show any errors, but it does not show up when I check it in phpMyAdmin. <?php $amount = $_POST["amount"]; $unit = $_POST["unit"]; $date = date('Y-m-d H:i:s'); $host = "localhost"; $user = "root"; $pass = ""; $db = "finance"; $table = "silver"; $mysqli = new mysqli($host, $user, $pass, 'finance'); if(!$mysqli) { echo "<div class=\"error\">"; echo "No connection can be established"; echo "</div>"; die(); } if (

Is it possible to use both MySQLi and PDO?

送分小仙女□ 提交于 2020-01-05 17:57:15
问题 Is it possible to use both MySQLi and PDO ? For example, to insert data using MySQLi and then select and work with it using PDO in other part of the project? I have a lot of insert/update code in MySQLi, but decided to switch to PDO? 回答1: Yes, it's possible. But keep in mind that you'd have two completely separated connections to the MySQL server in any case. The mysqli_* and PDO_MySQL extensions cannot (currently) share a single connection even though they use the same transport driver

PHP: Injection protection using prepared statements

让人想犯罪 __ 提交于 2020-01-05 11:02:36
问题 I am familiar with using PHP to perform mySQL queries. However, I have been using reg exps as protection against injection attacks. After reading several questions/answers here on SO, I've decided to opt for prepared statements instead. There's two options available (let me know if there are more): mysqli prepared statements PDO prepared staments Question 1 I am trying to understand the code examples given on the linked pages. For mysqli , Example #1 : if ($stmt = $mysqli->prepare("SELECT

PHP: Injection protection using prepared statements

别等时光非礼了梦想. 提交于 2020-01-05 11:02:20
问题 I am familiar with using PHP to perform mySQL queries. However, I have been using reg exps as protection against injection attacks. After reading several questions/answers here on SO, I've decided to opt for prepared statements instead. There's two options available (let me know if there are more): mysqli prepared statements PDO prepared staments Question 1 I am trying to understand the code examples given on the linked pages. For mysqli , Example #1 : if ($stmt = $mysqli->prepare("SELECT

login session destroyed after refresh

匆匆过客 提交于 2020-01-05 10:58:47
问题 I have made a log in script with some Google help but the problem is every time i refresh the page it gets log out and redirect me to the log in page. So basically i want this that a user is logged in after entering his details and not get logged out after a single refresh. my code is: <?php if(!isset($_SESSION)){ session_start(); } $username = mysqli_real_escape_string($con, $_POST['username']); $password = mysqli_real_escape_string($con, $_POST['password']); if ($username && $password) {

How to convert PDO to mysqli?

喜欢而已 提交于 2020-01-05 10:24:13
问题 I have a login screen in which the user inputs their username and password. I managed to connect to the database using PDO but I have to change it to mysqli. Could someone please help me convert it to mysqli. Thanks in advance. PDO: <?php try { $database = new PDO('mysql:host=localhost;dbname=myfiles', 'root', '',array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $query = "SELECT * FROM users WHERE Username = ? AND Password = ?"; $userParam = array($_POST["Uname"], $_POST["Pass"]); $st =

Mysqli bind - unknown number of parameters

匆匆过客 提交于 2020-01-05 10:09:13
问题 How to bind unknown number of parameters with Mysqli? For example, following my code: <?php include 'config.php'; $query = "SELECT * FROM table WHERE"; if(isset($_POST['r1'])) $query = $query." id = '$_POST['r1']'"; if(isset($_POST['r2'])) $query = $query." AND par2 = '$_POST['r2']'"; $e = mysqli_prepare($conf, $query); ?> How to do bind of parameters? 回答1: Prepared statements probably aren't the best way to do this. You can assemble a query just as you are doing, as long as you make sure

Select a recording based on the meta

两盒软妹~` 提交于 2020-01-05 08:59:27
问题 I have have the following tables Meta table id | recording_id | meta_key | meta_value Recording Table id | recording The recording_id on the meta_table is a foreign key that points towards a recording on the recording table. Now I have a associative array $metas from my $_GET with meta keys and values and I want to SELECT the recordings that match all the meta keys and values. How would I do that? This is what I have so far. How do I add an array into my bind param? And am I on the right

What is the benefit of using “begin_transaction” method in MySQLi?

落花浮王杯 提交于 2020-01-05 08:24:08
问题 I'm looking into rollback management with MySQLi, and I'm curious what is the benefit of begin_transaction() method. Many examples I look at skip it entirely by turning autocommit off, then executing some queries with success value returned, and testing a compound Boolean based on the return values to commit or rollback the multiple statements. It doesn't seem like the begin_transaction() method actually does any useful work in a scenario where we are looking to commit or rollback a group of

What is the right way to add a variable where-clause to this update function

笑着哭i 提交于 2020-01-05 08:09:34
问题 I'm made a database class in php. Now i was testing the update function in it. It returns an syntax error or an unknown column error depending on how the where-clause is formed. I tried: 'woord = \'uiteindelijk\'' and 'woord = \"uiteindelijk\"' and 'woord = "uiteindelijk"' and more I also tried different quotes and backsticks in de functions query but it al gave me the same errors. My question is what is the right way to form the where-clause is this example if it possible ofcourse. And if