mysqli

How do I display tables from a database?

馋奶兔 提交于 2020-05-24 05:13:31
问题 I'm trying to put the tables from MySQL database in a HTML page using PHP. I'm beginner in PHP and I face a problem to the mysqli_query function. This is my PHP code: // connect to the db $host = 'localhost'; $user = 'root'; $pass = ''; $db = 'testdb'; $connection = mysqli_connect($host, $user, $pass, $db) or die("cannot connect to db"); // show the tables $result = mysqli_query($connection, 'SHOW TABLES') or die ('cannot show tables'); while($tableName = mysqli_fetch_row($result)) { $table =

How do I display tables from a database?

吃可爱长大的小学妹 提交于 2020-05-24 05:12:08
问题 I'm trying to put the tables from MySQL database in a HTML page using PHP. I'm beginner in PHP and I face a problem to the mysqli_query function. This is my PHP code: // connect to the db $host = 'localhost'; $user = 'root'; $pass = ''; $db = 'testdb'; $connection = mysqli_connect($host, $user, $pass, $db) or die("cannot connect to db"); // show the tables $result = mysqli_query($connection, 'SHOW TABLES') or die ('cannot show tables'); while($tableName = mysqli_fetch_row($result)) { $table =

PHP changing fetch_field() to mysqli

早过忘川 提交于 2020-05-23 11:58:12
问题 My php knowledge is fairly limited but I've recently needed to update a number of web pages from an older version of php 5.2 to php 7.3. I've managed to update most of the mysql references to mysqli etc and get things working correctly, however there is one page that makes use of a calendar and I'm really struggling with this section and the fetch_field part in particular as any examples I have found don't seem to be in a similar format. The code I need to update is below; require_once(

SELECT COUNT(*) AS count - How to use this count

半腔热情 提交于 2020-05-22 07:50:51
问题 Instead of doing: $cars = $mysqli->query("SELECT * FROM cars"); $count = $cars->num_rows(); if ($count) { // is rows } I want to not have to select all rows or a single column, I simply want the count. In my head: $cars = $mysqli->query("SELECT COUNT(*) as count FROM cars"); But then how do I use that count value? I need to run an if statement on it. 回答1: It's not recommended to use reserved words for names in SQL. So I call the count result cnt instead. As your function is scalar, i.e. you

mysqli prepared statement num_rows returns 0 while query returns greater than 0

不想你离开。 提交于 2020-05-20 02:42:56
问题 I have a simple prepared statement for an email that actually exists: $mysqli = new mysqli("localhost", "root", "", "test"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $sql = 'SELECT `email` FROM `users` WHERE `email` = ?'; $email = 'example@hotmail.com'; if ($stmt = $mysqli->prepare($sql)) { $stmt->bind_param('s', $email); $stmt->execute(); if ($stmt->num_rows) { echo 'hello'; } echo 'No user'; } Result: echos No user when it should echo

I want to make a log in page using mysqli and i get this error “Cannot pass parameter 1 by reference”

主宰稳场 提交于 2020-05-18 04:35:42
问题 And this is my code: $q = "SELECT * FROM `my___passloging` WHERE `puser` = ? AND `ppass` = ?"; $procces = $this->db->prepare($q); $procces->bind_result("ss", $user, $pass); 回答1: You never executed your query. $procces = $this->db->prepare($q); $procces->execute(); // this part $procces->bind_result("ss", $user, $pass); Example from the manual: /* prepare statement */ if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) { $stmt->execute(); /* bind variables to

I want to make a log in page using mysqli and i get this error “Cannot pass parameter 1 by reference”

放肆的年华 提交于 2020-05-18 04:35:26
问题 And this is my code: $q = "SELECT * FROM `my___passloging` WHERE `puser` = ? AND `ppass` = ?"; $procces = $this->db->prepare($q); $procces->bind_result("ss", $user, $pass); 回答1: You never executed your query. $procces = $this->db->prepare($q); $procces->execute(); // this part $procces->bind_result("ss", $user, $pass); Example from the manual: /* prepare statement */ if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) { $stmt->execute(); /* bind variables to

I want to make a log in page using mysqli and i get this error “Cannot pass parameter 1 by reference”

旧街凉风 提交于 2020-05-18 04:34:05
问题 And this is my code: $q = "SELECT * FROM `my___passloging` WHERE `puser` = ? AND `ppass` = ?"; $procces = $this->db->prepare($q); $procces->bind_result("ss", $user, $pass); 回答1: You never executed your query. $procces = $this->db->prepare($q); $procces->execute(); // this part $procces->bind_result("ss", $user, $pass); Example from the manual: /* prepare statement */ if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) { $stmt->execute(); /* bind variables to

Warning: mysqli_connect(): (HY000/1044): Access denied for user ''@'localhost' to database 'dbtest' [closed]

ε祈祈猫儿з 提交于 2020-05-17 08:33:33
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 14 days ago . When i try to connect to my sql server, it gives me the error: Warning: mysqli_connect(): (HY000/1044): Access denied for user ''@'localhost' to database 'dbtest'. I just created the user and gave it all permissions, but i still dosent work. Before i used another account, but i couldn't change the

Error when using mysqli_select_db and mysqli_connect

為{幸葍}努か 提交于 2020-05-14 08:45:18
问题 I am switching to mysqli, because mysql_* functions are not supported anymore. When I try to connect to my database, I get an error. Here is my code. <?php //ob //ob_start(); //session session_start(); //connect to database $error = "Could not connect to database"; mysqli_connect('','************','**********') or die($error); mysqli_select_db('********************') or die($error); $session_username = $_SESSION['username']; $session_coin = $_SESSION['coins']; ?> Error: Could not connect to