mysqli

PHP mysqli_query() expects parameter 1 to be mysqli, object given in [duplicate]

一世执手 提交于 2021-02-01 05:13:30
问题 This question already has answers here : mysqli_query() expects parameter 1 to be mysqli, object given (3 answers) Closed 8 days ago . I have this code class Db_conn { private $sn = 'localhost'; private $un = 'root'; private $up = ''; public function connect(string $db_n){ $conn = mysqli_connect($this->sn, $this->un, $this->up, $db_n); if (!$conn) { die("Připojení se nezdařilo: " . mysqli_error($conn)); } else { return $conn; } } } And this code public function update($query){ $dbconn = new

mysqli_query() expects parameter 1 to be mysqli, object given

早过忘川 提交于 2021-01-29 22:30:01
问题 I'm trying to create a class which can be used for connecting to MySQL database. This is my code: The class: <?php class createCon { var $host = 'localhost'; var $user = 'root'; var $pass = ''; var $db = 'example'; var $myconn; function connect() { $con = mysqli_connect($this->host, $this->user, $this->pass, $this->db); if (!$con) { die('Could not connect to database!'); } else { $this->myconn = $con; echo 'Connection established!';} return $this->myconn; } function close() { mysqli_close(

mysqli prepared statement with while loop

我的未来我决定 提交于 2021-01-29 22:01:13
问题 I am trying to do an extremely simple query using mysqli. It is driving me mad! I just want $data to be an array of the values from the sql query. This is my code... $req = $app->request(); $hashtag = $req->get('hashtag'); require_once 'Slim/lib/database.php'; $db = connect_db(); $statement = $db->prepare("SELECT `content` FROM `posts` WHERE `content` LIKE ?"); $newhashtag = '%#' . $hashtag . '%'; $statement -> bind_param("s", $newhashtag); $statement -> execute(); $statement -> bind_result(

mysqli prepared statement with while loop

≯℡__Kan透↙ 提交于 2021-01-29 17:18:16
问题 I am trying to do an extremely simple query using mysqli. It is driving me mad! I just want $data to be an array of the values from the sql query. This is my code... $req = $app->request(); $hashtag = $req->get('hashtag'); require_once 'Slim/lib/database.php'; $db = connect_db(); $statement = $db->prepare("SELECT `content` FROM `posts` WHERE `content` LIKE ?"); $newhashtag = '%#' . $hashtag . '%'; $statement -> bind_param("s", $newhashtag); $statement -> execute(); $statement -> bind_result(

mysqli last insert id

*爱你&永不变心* 提交于 2021-01-29 15:56:41
问题 I would like to associate the image with firstname, lastname...how can I retrieve the last rowand use it to insert to the other table? I tried $image = $mysqli->insert_id; then binding but it doesn't work. Can someone help me out? $image = $mysqli->insert_id;//this should come from table2 $stmt = $mysqli->prepare(" insert into table1 (username, firstname, lastname, image) select ?,?,?,image from table2 t2 where username = ? and t2.id = ? "); $stmt->bind_param('sssss', $username, $fname,

The used command is not allowed with this MariaDB version with local_infile ON

隐身守侯 提交于 2021-01-29 14:25:15
问题 I know, there are a couple of questions out there, that are focusing on the same Issue, but all suggested fixes are not working for me. I am running a PHP script in which I a trying to insert a CSV file into my DB using LOAD DATA INFILE like this $db = mysqli_init(); mysqli_options($db, MYSQLI_OPT_LOCAL_INFILE, true); mysqli_real_connect($db, $db_host, $db_username, $db_password, $database); $sql = "LOAD DATA LOCAL INFILE '" . $tpl_vars['filename'] . "' " . "INTO TABLE " . $table_name . " " .

Updating database using PHP without empty values from HTML form

旧巷老猫 提交于 2021-01-29 13:48:28
问题 I want to update my SQL db without empty values from my form. That's what I've got: if(isset($_POST['account_details_submit'])) { $user_id = array_values($_SESSION['user_info'])[9]; $edited = date('d.m.Y h:i a'); if(isset($_POST['account_details_first_name']) and !empty($_POST['account_details_first_name'])) { $add .= " and `first_name` = '$_POST[account_details_first_name]'"; } if(isset($_POST['account_details_last_name']) and !empty($_POST['account_details_last_name'])) { $add .= " and

mysqli_query single query gerenating PHP fatal error: Allowed memory size exhausted

ぃ、小莉子 提交于 2021-01-29 10:25:58
问题 I have a Mysql table (named "base") with 3 million records , which is composed of only 3 int(10) fields . When I try to run this simple query $result = mysqli_query($db, 'SELECT * FROM base') , php shows the error: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 10485768 bytes) in C:\xampp\htdocs\combina.php on line 17 I think mysqli_query should not load all the table records into memory, right? So why the memory overflow? I'm using XAMPP installation on

Do mysqli_result need an alive connection to seek results?

。_饼干妹妹 提交于 2021-01-29 08:58:36
问题 We noticed that a call to our API endpoint usually have multiple duplicated MySQL queries for SELECT statements (sometimes hundreds). So we decided to create a hashmap to store the mysqli_result and check if a given query has already been done and return the result saved in our map. My question is: do mysqli_result maintain a reference to our connection? Would this actually help us to avoid overloading our database with queries that have already been requested unnecessarily? If the mysqli

How to return mysqli connect_error over 2 function in 2 classes PHP [duplicate]

廉价感情. 提交于 2021-01-29 08:55:32
问题 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 7 months ago . I have the dbc.inc.php file. inside of it there are connect function that connects me to the DB. In the test.inc.php file i have the runQuery function inside of a "Test" class. The "Test" class extends from the "Dbc" class allocated in the dbc.inc.php file. The runQuery($db, $sql) runs