mysqli persistent connection

Support for this was introduced in PHP 5.3. For versions before this, PDO and – god forbid – the mysql extension are the only options. To quote the manual: Unlike the mysql extension, mysqli does not provide a separate function for opening persistent connections. To open a persistent connection you must prepend p: to the … Read more

PHP prepared statements and transactions in a loop [duplicate]

Your loop can be optimized by pulling the prepare and bind_param statements out of the loop. $value = null; $mysqli->autocommit(FALSE); $sql = “INSERT INTO temp (`fund_id`) VALUES (?)”; $stmt = $mysqli->prepare($sql); $stmt->bind_param(‘i’, $value); foreach ($pdata as $value) { $stmt->execute(); } $mysqli->commit(); You have turned off autocommit with your autocommit(FALSE) line and therefore don’t need to … Read more

PHP: mysql v mysqli v pdo [closed]

The design of the mysql_query function is such that you’ve got to be careful to escape each and every bit of data you’re injecting into it, and if you miss even one your entire application can be destroyed by an automatic SQL vulnerability exploit tool. Both mysqli and PDO support placeholders which are required to … Read more

Set character set using MySQLi

It’s the same: $mysqli->query(“SET NAMES ‘utf8′”); From the manual: This is the preferred way to change the charset. Using mysqli::query() to execute SET NAMES .. is not recommended. $mysqli->set_charset(“utf8”); is just enough, let the mysqli db driver do the thing for you.

Which is fastest in PHP- MySQL or MySQLi?

The MySQL extension is very slightly faster than MySQLi in most benchmarks I’ve seen reported. The difference is so slight, however, that this should probably not be your criterion for deciding between the two. Other factors dwarf the difference in performance between mysql and mysqli. Using mod_php or FastCGI, a bytecode cache like APC, or … Read more

Call to undefined method mysqli_result::fetch()

The variable $stmt is an object of the mysqli_stmt class. This class has a method called fetch() which returns a boolean (true/false). It is used only in conjunction with bind_result() $stmt = $conn->prepare(‘SELECT myCol, myOtherCol FROM myTable WHERE dt=?’); $stmt->bind_param(“s”, $date); $stmt->execute(); // The columns in SQL will be bound to the PHP variables $stmt->bind_result($variable1, … Read more