mysqli

mysqli_multi_query and mysql transactions

社会主义新天地 提交于 2019-12-25 00:33:57
问题 I'm experimenting with transactions for the first time in mySQL. I am wondering if it is safe to use mysqli_multi_query for this purpose. That is, can I assume that if any of the SQL statements fails, everything will be rolled back? $query = " START TRANSACTION; (a bunch of SQL statements) COMMIT; "; if (mysqli_multi_query($connection, $query)) { do { if ($result = mysqli_store_result($connection)) mysqli_free_result($result); } while (mysqli_next_result($connection)); } Thanks, 回答1: Yes,

Finding out why a mysqli INSERT failed - which unique index was duplicated?

╄→尐↘猪︶ㄣ 提交于 2019-12-25 00:17:19
问题 I'm currently writing a REST style php server that needs to allow user registration. The basics are working but I am focusing on error handling now. My users table has a unique index on the 'user_name' field and the 'user_email' field. When I try to insert a duplicate value I can read the error and get a string like Duplicate entry 'noggin182' for key 'user_name' I need to translate this into something that I can display to the user. Is there is an easy way to get more details of why the

mysqli_stmt::bind_param()Number of elements in type definition string doesn't match number

不打扰是莪最后的温柔 提交于 2019-12-25 00:10:01
问题 i have a problem with using mysqli_stmt::bind_param(). Can someone help me? Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables... I am beginner in php. Thanks public function init($cards,$table,$seats) { $operation = $this->operation($table, $seats); return $this->insertCards($cards,$operation,count($cards)); } public function operation($table, $seats) { $operation = "insert into ".$table."(";

Check if the username already exists with MySQLi

微笑、不失礼 提交于 2019-12-24 22:00:55
问题 I try to check if the username and email from input fields already exists in my database before to create a new user. this is login.php : <?php session_start(); $pseudo = $_POST['pseudo']; $mail = $_POST['mail']; $pseudo=mysql_real_escape_string($pseudo); $pseudo=ltrim($pseudo); $pseudo=rtrim($pseudo); $mail=mysql_real_escape_string($mail); $mail=trim($mail); $sql=mysqli_connect('localhost','root','','bdd_name'); $query=("SELECT COUNT(*) FROM t_people WHERE 'PEO_PSEUDO'='".$pseudo."' OR 'PEO

Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in OpenCart [duplicate]

放肆的年华 提交于 2019-12-24 21:07:13
问题 This question already has answers here : php, mysql - Too many connections to database error (6 answers) Closed 5 years ago . Guys i am having errors in my opencart website, but actually the problem is that this error also displays my database login and password. How can i fix this problem. The error raised is like Fatal error: Uncaught exception "ErrorException" with message "Error: Could not make a database link (1040) Too many connections" in /home/*******/public_html/system/database

Fatal Error when trying to view PHP data as JSON with XAMPP

≡放荡痞女 提交于 2019-12-24 20:11:34
问题 The following error is present when trying to view api.php using localhost: Fatal error: Assignments can only happen to writable values in /opt/lampp/htdocs/MyApi/api.php on line 27 I had a few errors in my code that I thought would have been contributing to this error (one of which was on line 27), however, still no joy. When I comment out line 27, the error moves on to line 28, and so forth. I have also tried to change the name of my array to 'job' as it was originally the same name as my

mysqli_connect problem

纵然是瞬间 提交于 2019-12-24 19:11:47
问题 This is my login script; <?php $username = $_POST['username']; //kullanici adi $password = $_POST['password']; //parola $msg =''; if(isset($username, $password)) { ob_start(); include('ayar.php'); // güvenlik amaçli sql injection önlemek için sinirlama koy $dbC = mysqli_connect($vthost, $vtkullanici, $vtsifre, $vtadi) or die('Veritabanina baglanilamadi'); $myusername = stripslashes($username); $mypassword = stripslashes($password); $myusername = mysqli_real_escape_string($dbC, $myusername);

Insert data into MySql DB

≡放荡痞女 提交于 2019-12-24 19:04:50
问题 I'm creating a class and I have a function with which I want to insert some data into an table from some inputs. It works if I check the table but I keep getting the error "number of arguments in prepare doesn't match the no of arg in bind_result". Also I don't know if my method is correct .. private function insertData($foldName,$foldClass,$foldLink) { $sql = "INSERT INTO folders (folder_name,folder_class,folder_link) VALUES ('$foldName','$foldClass','$foldLink')"; if($stmt = $this->connect-

MySQLi: prepared statement to return nested arrays

邮差的信 提交于 2019-12-24 19:03:47
问题 I use this class method to return a nested/ multi-dimensional array, public function fetch_all_stmt($sql,$types = null,$params = null) { # create a prepared statement $stmt = parent::prepare($sql); if($stmt) { if($types&&$params) { $bind_names[] = $types; for ($i=0; $i<count($params);$i++) { $bind_name = 'bind' . $i; $$bind_name = $params[$i]; $bind_names[] = &$$bind_name; } $return = call_user_func_array(array($stmt,'bind_param'),$bind_names); } # execute query $stmt->execute(); # these

How to update session empty value

荒凉一梦 提交于 2019-12-24 18:38:53
问题 I am creating message conversation delete script in PHP MYSQLI. I am trying to update session empty value. My problem I can update from_delete column. But I can't update incoming message column to_delete . I want to update from_delete or to_delete columns empty session value. Here is my pm table id from_id to_id msg sent_date from_delete to_delete 1 2 3 hi how are you? 2019-12-05 04:14:20 0 3 2 3 2 fine 2019-12-05 05:15:58 0 2 3 2 3 hi 2019-12-05 03:20:34 0 3 4 5 2 hi 2019-12-05 08:30:40 0 2